2
我用這個僞類,使Ajax請求到服務器:jQuery的Ajax請求返回的錯誤和狀態0
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-19 19:57:58
問題是什麼? – katrin 2012-09-06 09:23:19