Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
programmieren:javascript:alpinejs_ajax_beispiel [2022/09/14 08:06] jgehrkeprogrammieren:javascript:alpinejs_ajax_beispiel [2022/12/17 12:28] (current) – external edit 127.0.0.1
Line 48: Line 48:
  xhttp.setRequestHeader("Content-Type", "application/json");  xhttp.setRequestHeader("Content-Type", "application/json");
  xhttp.onreadystatechange = function() {  xhttp.onreadystatechange = function() {
- if(this.readyState == 4 && this.status == 200) {+ const is_call_success = (this.readyState == 4 && this.status == 200) ? true : false; 
 +  
 + if( is_call_success ) {
  const response_json = JSON.parse( this.response );  const response_json = JSON.parse( this.response );
- console.log( "Antwort: " ); 
- console.log( response_json ); 
- 
  /*  /*
       in current context 'this' would refer to the XMLHttpRequest Object       in current context 'this' would refer to the XMLHttpRequest Object
Line 58: Line 57:
      So we be bound the current alpine.js object to a global window variable      So we be bound the current alpine.js object to a global window variable
  */  */
- window.this_alpinejs_module.repsonse_json = response_json; // <-- Important+ window.this_alpinejs_module.repsonse_json = response_json; // working version of this.repsonse_json
   
  return true;  return true;

Page Tools