我使用这个伪类向服务器发出 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 代码?