Home > front end >  Why do the ajax callback data is empty
Why do the ajax callback data is empty

Time:05-25

This code is the callback data why is an empty
Var data1 has been set as a global variable

The first to the console. The log (data1) can display the callback data
The second console. The log (data1) to show the empty data


Var data1=new Array ();
var xhr=new XMLHttpRequest();
XHR. Open (' get ', './XXXX. PHP ');

//XHR. SetRequestHeader (' the content-type ', 'application/x - WWW - form - urlencoded ");

XHR. Onreadystatechange=function () {
If (XHR. ReadyState==4 & amp; & XHR. Status==200) {
Var arr=XHR. The responseText;
Data1=JSON. Parse (arr);
//this can show the callback data
The console. The log (data1);
}
}
XHR. Send (null);
//2 this display is empty
The console. The log (data1);


The barrel of the teacher to give directions
  •  Tags:  
  • Ajax
  • Related