我使用这个伪类向服务器发出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");
};
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;
}当我实例化一个新对象时,我用它来加载一个请求,它总是返回给我错误,状态码是0。服务器正确地生成XML文档。为什么我拿不回正确的200代码?
发布于 2010-04-20 01:33:38
如果这发生在您第二次调用require时,这是因为对abort()的调用导致您的回调被调用,状态码为0。稍后,您应该会获得第二个请求的正确结果。
在jQuery 1.4中也有一个错误,在中止请求后调用success回调。参见my answer to 。
与这个问题无关的是,您的代码中有一些变量(timer和ajaxCall)似乎既可以用前导下划线引用,也可以不用前导下划线引用。
https://stackoverflow.com/questions/2669436
复制相似问题