Tôi muốn hiểu lời gọi AJAX bên dưới, về phương pháp complete()
;Sử dụng thành công() hoặc hoàn thành() trong cuộc gọi AJAX
Khi tôi thay complete()
với success()
, tôi nhận được một sản phẩm nào responseText cũng giống như với phương pháp AJAX error()
.
Mặt khác, khi tôi rời phương thức complete()
ở đó, mọi thứ hoạt động như mong đợi.
Có phải là success()
trả về sớm hơn complete()
?
$("#formnaw").submit(function() {
var fnc = invoerFnc.attr("value");
var vnaam = invoerVnaam.attr("value");
var anaam = invoerAnaam.attr("value");
var str1 = invoerStr1.attr("value");
var nr1 = invoerNr1.attr("value");
var pc1 = invoerPc1.attr("value");
var pl1 = invoerPl1.attr("value");
var tel1 = invoerTel1.attr("value");
var mob1 = invoerMob1.attr("value");
var em1 = invoerEm1.attr("value");
var goknop = $("#formnaw > .instelling_go");
//we deactiveren de submit knop tijdens het verzenden
goknop.attr({
disabled: true
});
goknop.blur();
//stuur de post variabelen naar livetabs.php
$.ajax({
type: "POST",
url: "registraties/instellingenact.php",
data: "actie=wijzignaw&vnaam=" + vnaam + "&anaam=" + anaam + "&functie=" + fnc + "&straat=" + str1 + "&nr=" + nr1 + "&postcode=" + pc1 + "&plaats=" + pl1 + "&tel=" + tel1 + "&mob=" + mob1 + "&email=" + em1,
timeout: 5000,
success: function(data, textStatus) {
alert('bij success');
//doe iets
} //EINDE success
,
error: function(XMLHttpRequest, textStatus, errorThrown) {
if (textStatus == 'timeout') {
//doe iets
} else if (textStatus == 'error') {
//doe iets
}
//her-activeer de zend knop
goknop.attr({
disabled: false
});
} //EINDE error
,
complete: function(data) {
updatelijst.append(data.responseText + "<br>");
if (data.responseText.indexOf("Fout") != -1) {
$('#formnaw').find('td.foutnr1').prepend(data.responseText);
} else {
updatelijst.animate({
opacity: 'show'
}, 1000, function() {});
}
//her-activeer de zend knop
goknop.attr({
disabled: false
});
} //EINDE complete
}); //EINDE ajax
//we stoppen het standaard gedrag van een submit, zodat de pagina niet wordt vernieuwd.
return false;
});
cảm ơn, nhưng để rõ ràng, tôi có phải sử dụng mã để thực thi theo một tùy chọn hoàn chỉnh và không thành công hay không. Và tùy chọn lỗi cũng sẽ làm việc với tùy chọn hoàn chỉnh một mình? –
hoặc, nó cho thấy rằng tôi không nhận được một sự thành công responsecode, lạ? –