[英]Ajax ready state : 0 always in javascript
This the part of my code where I create the request. 这是我创建请求的代码的一部分。 ( I do not want to use jquery)
(我不想使用jQuery)
var xr = new XMLHttpRequest();
console.log(xr);
xr.onreadystatechange = function () {
console.log(xr.readyState,xr.status);
if(xr.readyState == 4 && xr.status == 200) {
var data=xr.responseText;
alert(data.innerHTML);
console.log(data);
}
var params ="param1="+movieName+"¶m2"+movieGenre ;
xr.open("GET","./saveMovie.php"+"?"+params,true);
xr.send();
}
You need to open and sed the XHR outside the callback function. 您需要在回调函数外部打开并设置XHR。
var xr = new XMLHttpRequest();
console.log(xr);
xr.onreadystatechange = function () {
console.log(xr.readyState,xr.status);
if(xr.readyState == 4 && xr.status == 200) {
var data=xr.responseText;
alert(data.innerHTML);
console.log(data);
}
}
var params ="param1="+movieName+"¶m2"+movieGenre ;
xr.open("GET","./saveMovie.php"+"?"+params,true);
xr.send();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.