Ajax意味着異步,但它看起來像停止我的JavaScript執行或至少暫停它並恢復響應。僅限Chrome瀏覽器:ajax凍結我的JavaScript執行
HTML值
<input value="foo" data-loading-text="bar" class="foo">
擴展的jQuery - >
$.fn.bootstrapButton= function(type){
$el = $(this);
loadingText = $el.attr("data-loading-text");
currentValue = $el.val();
if(type === "loading")
$el.attr("data-loading-text",currentValue)
.val(loadingText)
.prop("disabled", true)
else if(type === "reset")
$el.val(loadingText)
.prop("disabled", false)
.attr("data-loading-text", currentValue)
}
函數調用 - >
save= function (name){
$save = $(".ok")
$save.bootstrapButton("loading")
$.ajax({
type: 'POST'
url: '/server'
cache: false
dataType: 'json'
data:"ss"
success: function(response){
alert("success")
}).always(function(){
$save.bootstrapButton("reset")
})
}
我延長jQuery用戶界面的按鈕問題的引導程序的按鈕堂妹。但是 - 當這個執行的時候,我看不到加載文本,直到ajax請求完成! da faq !.異步不是真正的異步?
順便說一句,代碼工作沒有任何毛刺(我可以看到加載文本)與這個小的修改。
save= function (name){
$save = $(".ok")
$save.bootstrapButton("loading")
setTimeout(funtion(){
$.ajax({
type: 'POST'
url: '/server'
cache: false
dataType: 'json'
data:"ss"
success: function(response){
alert("success")
}).always(function(){
$save.bootstrapButton("reset")
})
},100)
}
即,在100毫秒的延遲下,加載文本出現!,什麼給出?
我注意到這發生在Chrome而不是Firefox。你是Chrome開發人員嗎? – Andy 2015-02-24 15:06:56
是否有可能將這些ajax調用的'async'選項設置爲false? jQuery ajax調用支持一種使呼叫同步的方法。因此,如果將異步設置爲false,這可以解釋它...嘗試將mannualy設置爲true(async:true,...)。只是猜測在這裏,我不能更有幫助 – astian 2015-02-24 15:07:09
警報與它無關..是的,看到在鉻。 havnt檢查了火狐 – 2015-02-24 15:07:53