[英]Javascript Alert interfering with Ajax
我正在使用JQuery Ajax從服務器獲取腳本。
$.ajax({
url: src,
type: "GET",
dataType: "script",
timeout: transaction_timeout
}).done(function(){})
.fail(function() { alert("Error in server");})
.always(function() {Aegis.end();});
然后服務器返回一個我需要覆蓋它的回調函數,以獲得如下結果:
function callbackfunction(msg){
var obj = jQuery.parseJSON(msg);
var result = obj.result;
}
一切正常,直到我在回調函數中發出警報
function callbackfunction(msg){
var obj = jQuery.parseJSON(msg);
var result = obj.result;
alert(result);
}
現在,如果用戶在超時之前未單擊“確定”,則會發生超時失敗,並且將提醒“服務器中的錯誤”。
同時,如果調用callback函數,則意味着我的事務成功完成。 我該如何解決這個問題?
一個解決方案是:
setTimeout(function(){alert(result);},0);
但最好的可能就是根本不使用alert
。 你為什么不使用console.log ?
編輯:如果您想要的是以簡單的方式顯示消息,那不是那么難:
$('<div>').text('message!').css({position:'fixed', top:0, background:'yellow'})
.click(function(){$(this).remove()}).appendTo(document.body);
(單擊時消息消失)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.