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