我想在點擊提交按鈕時觸發ajax調用。同時,我只想隱藏提交按鈕並顯示一個gif圖像,直到ajax完成。但提交按鈕點擊後需要一段時間才能隱藏。我不知道,但爲什麼?jQuery的hide()和show()方法工作不夠快
function exemptProductAjaxCall() {
$("#delistSubmit").hide("fast");
$("#edit-icon").show("fast");
var days, pId, remarks;
days = $("#exemptDays").val();
pId = $('#exempPid').val();
remarks = $("#remarks").val();
pIdParam = [pId];
$.ajax({
type: "POST",
url: "abc.php",
cache: false,
async: false,
data: {dispatch: 'myphp.pidExempt', pIds: pIdParam, exemptDays: days, remarks: remarks, callAjax: 1},
error: function (data, textStatus, jqXHR)
{
//error msg
var err = eval("(" + data.responseText + ")");
alert('Ajax Error: ' + err.Message);
}
}).done(function (msg) {
var resPonse = JSON.parse(msg);
if (resPonse['success'] == 1)
{
alert('Success: ' + resPonse['message']);
$("#exemptDays").val(1);
$('#exempPid').val('');
$("#remarks").val('');
} else
{
if (typeof resPonse['message'] === 'undefined')
alert('Error: Unknown Error');
else
alert('Error: ' + resPonse['message']);
}
});
$("#edit-icon").hide();
$("#delistSubmit").show();
}
<input type="button" id="delistSubmit" value="Submit" onClick="exemptProductAjaxCall();" style="padding-bottom: 41px;">
<img id="edit-icon" style="-webkit-user-select:none;height:36px;width:36px;float:left;margin-right:40px;display:none;" src="banners/ajax-load-black.gif">
如果從exemptProductAjaxCall()中除去$(「#delistSubmit」),則會發生什麼情況。hide(「fast」);和$(「#edit-icon」)。show(「fast」)?仍然很慢? –