![](/img/trans.png)
[英]jquery ajax call returning an error with readystate 4, status 200, statustext ok
[英]JQuery ajax() done / fail callbacks not returning upon status 200
我正在嘗試使用JQuery將表單數據發布到遠程servlet。 我可以看到服務器接收到數據並且還返回狀態代碼200和響應字符串“ {result:'success'}”,但是ajax調用不會返回完成函數或失敗函數(如果我添加了always函數可以看到它被調用了)這是客戶端的代碼段:
`
var dataParams = 'email='+email+'&password='+password;
var url = 'http://127.0.0.1:8888/signup';
var jxhr = $.ajax({
type : "POST",
url : url,
data : dataParams,// serializes the form's elements.
dataType: "json",
done: function() {
console.log("done!");
hideSignUp();
showThankYou(); },
fail: function() {
console.log("fail!");
}
});
`
似乎我錯過了某些東西,但似乎找不到什么。 請注意,我正在使用JQuery 1.8.3,因此不贊成使用成功。 有什么想法嗎?
嘗試:
var url = "http://127.0.0.1:8888/signup";
var jxhr = $.ajax({
type : "POST",
url : url,
data : dataParams,// serializes the form's elements.
dataType: "json"
}).done(function() {
console.log("done!");
hideSignUp();
showThankYou();
}).fail(function(jqXHR, textStatus) {
console.log(textStatus);
});
嘗試鏈接回調,而不是將它們設置為對象字段:
$.ajax({
type : "POST",
url : url,
data : dataParams,// serializes the form's elements.
dataType: "json"
}).done(function (xhrResponse) {
console.log("done!");
hideSignUp();
showThankYou();
}).fail(function (xhrResponse, textStatus) {
console.log(textStatus);
}).always( function () {
console.log("I'm done with this.");
});
通過鏈接回調,可以保證至少執行一個(完成)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.