[英]AJAX request is sent multiple times
還有很多與此問題相關的帖子,但是我找不到可以解決我的問題的帖子。 AJAX請求被多次發送。
var checkAllStatus = function () {
$.ajax({
cache: false,
type: "POST",
url: "@Url.Action("CheckAllStatus")",
dataType: 'json',
contentType: "application/json; charset=utf-8",
success: function (data) {
if (data == true) {
DoCloseDay();
}
else {
window.location.href(root + 'Close');
}
},
error: function (xhr, ajaxOptions, thrownError) {
alert('Error: ' + thrownError);
}
});
};
function DoCloseDay() {
var statesProgress = $("#loading-progress");
var successMsg = $("#success-msg");
statesProgress.show();
$.ajax({
cache: false,
type: "POST",
url: "@Url.Action("Close")",
dataType: 'json',
contentType: "application/json; charset=utf-8",
success: function (data) {
if (data == true) {
window.location.href(root + 'Close');
}
},
error: function (xhr, ajaxOptions, thrownError) {
alert('Error: ' + thrownError);
}
});
}
控件將根據以下條件啟用和禁用。 我不認為這會使請求發送兩次
@if (Model.SafeDropsTask.Status == 'SAVED' )
{
<button type="button" id="close" name="close" onclick="checkAllStatus();">
<i class="fa fa-check-circle"></i> Close
</button>
}
else
{
<button type="button" id="close" name="close" onclick="checkAllStatus();" disabled="disabled">
<i class="fa fa-check-circle"></i> Close
</button>
}
我已經找到了我所面臨的問題的原因。 由於瀏覽器運行緩慢,因此用戶能夠多次單擊該按鈕。 為了防止這種情況,我在用戶第一次單擊后立即禁用了該按鈕。 非常感謝提供寶貴意見的人們。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.