サーバーにいくつかの AJAX リクエストを実装しています。リクエスト タイプとパラメータは 2 つのケースでまったく同じですが、サーバーからのレスポンス タイプは異なります。
ケース 1 :
これは、titanium ネットワーク http クライアントを使用した Titanium での実装です。
var xhr = Ti.Network.createHTTPClient({
onload : function() {
alert('sucess');
},
onerror : function(e) {
alert('error');
},
timeout : 5000
});
var main_url = "http://localhost:3000/shops/560/login.json?api_token=some_token&customer[phone_number]=9988776655&customer[pin]=9876";
xhr.open('GET', main_url);
xhr.send();
これは完全に応答を返し、私にとってはうまくいっているようです。
ケース 2 :
これは、JQuery AJAX メソッドを使用したローカル ファイルでの実装です。
var main_url = "http://localhost:3000/shops/560/login.json?api_token=some_token&customer[phone_number]=9988776655&customer[pin]=9876";
$.ajax({
url: main_url,
type: "GET",
dataType: "json",
timeout: 5000,
success: function(data, status, xmlstatus) {
alert("success");
},
error: function(data, status, xmlstatus){
if (t === "timeout") {
alert("timeout");
} else {
alert("some error");
}
}
});
ただし、ブラウザのCROSS DOMAIN ポリシーにより、返されます
XMLHttpRequest cannot load http://localhost:3000/shops/560/login.json?api_token=some_token&customer[phone_number]=9988776655&customer[pin]=9876. Origin null is not allowed by Access-Control-Allow-Origin.
したがって、これを回避するために、別のパラメーターを追加しました
&callback = ?
しかし、それでも戻ってきます
alert('some error');
どこで問題が発生しているのかを把握できません。URL、パラメーター、タイプがすべて同じ場合。
- - - - - - - -編集 - - - - - - -
内部を掘り下げると、応答が得られます。
console.log(data) => parsererror
と
console.log(xmlstatus) => jQuery164023596301255747676_1335786441349 was not called