Php jQuery Ajax请求返回错误和状态0
我使用这个伪类向服务器发出Ajax请求:Php jQuery Ajax请求返回错误和状态0,php,javascript,jquery,ajax,http-status-codes,Php,Javascript,Jquery,Ajax,Http Status Codes,我使用这个伪类向服务器发出Ajax请求: function RequestManager(url, params, success, error){ //Save this Ajax configuration this._ajaxCall = null; this._url= url; this._type = params.type; this._success = function(){ alert("ok"); };
function RequestManager(url, params, success, error){
//Save this Ajax configuration
this._ajaxCall = null;
this._url= url;
this._type = params.type;
this._success = function(){
alert("ok");
};
this._error = function(){
alert("ko");
};
}
RequestManager.prototype = {
require : function(text){
var self = this;
this._ajaxCall = $.ajax({
url: this._url,
type: this._type,
data: text,
success: function(xmlResponse){
var responseArray = [];
var response = _extractElements(xmlResponse, arrayResponse);
self._success(response);
},
error: self._error,
complete : function(xhr, statusText){
alert(xhr.status);
return null;
}
});
}
这是将要加载的PHP:
<?php
header('Content-type: text/xml');
//Do something
$done = true;
$response = buildXML($done);
$xmlString = $response->saveXML();
echo $xmlString;
function buildXML ($done){
$response = new SimpleXMLElement("<response></response>");
if($done){
$response->addChild('outcome','ok');
}
else {
$response->addChild('outcome', 'ko');
}
return $response;
}
saveXML();
echo$xmlString;
函数buildXML($done){
$response=新的SimpleXMLElement(“”);
如果($完成){
$response->addChild('outcome','ok');
}
否则{
$response->addChild('outcome','ko');
}
返回$response;
}
当我实例化一个新对象,并使用它加载一个请求时,它总是返回给我错误,状态代码为0。服务器正确地生成XML文档。为什么我无法获取正确的200代码?如果在第二次调用
require
时发生这种情况,那是因为调用abort()
会导致调用状态代码为0的回调。您应该稍后获得第二个请求的正确结果
在jQuery1.4中还有一个bug,在中止请求后调用success
回调。看
与此问题无关,您的代码中有一些变量(
timer
和ajaxCall
)似乎在引用时带有或不带前导下划线。好的,问题出在另一段代码中,无论如何,您的信息都是有用的。谢谢