我有以下代碼:jQuery的阿賈克斯。員額()問題
$(document).ready(function() {
console.log("Document ready...");
$.post("...file.asmx/HelloWorld", function(data) {
console.log("Post Successful");
});
});
我得到以下控制檯輸出:
[10:01:44.528] Document ready...
[10:01:44.601] POST ..file.asmx/HelloWorld [HTTP/1.1 200 OK 103ms]
我的問題是,爲什麼是第二個日誌呼叫不執行?看起來帖子是成功的,並且該函數應該執行。我使用的是Firefox。
另外:
$(document).ajaxError(function(event, jqxhr, settings, exception) {
console.log("Triggered ajaxError handler.");
console.log(exception);
});
當我嘗試登錄的例外,我得到我的控制檯中的空行。
根據從服務返回什麼類型的數據,你可能想傳遞一個第四個參數來'$ .post()'表示響應的格式(JSON,HTML,文本等)。如果你不這樣做,jQuery會猜測如何根據它的Content-Type頭解析響應。另外,我認爲在jQuery的最新版本中,空的響應被認爲是無效的JSON,而它用於沒有問題 – Ian