没有"警告" ajaxStart没有正常运行

时间:2014-12-04 20:31:18

标签: javascript jquery ajax

这是我的代码,用于在ajax仍在进行时尝试放置加载程序。我的问题是,如果我发出警报,我就会得到我需要的东西。但是,如果我删除警报,它不会显示“正在加载...”。 使用Javascript:

 $(document).ajaxStart(function() {
   $('#loading').html("Loading...");
   console.log("hii");
   alert("gg");
 });

HTML:

<div id="loading"></div>

也许,我在某处做错了但我无法弄清楚为什么每当我发出警报时,它会显示加载页面并在我删除警报时消失。

任何想法/解决方案?

以下是ajax请求示例

$.ajax({
    url: xyz,
    data: dataObj,
    type: request_type,
    async: async_status,
    datType: "json",
    timeout: 10000,
    success: function(data){
        DEBUG && console.log("[OK] .", data);

        // Show error messages from server if they exist
        if (data.status == "failure"){
            if (data.code == "104"){
                alert("Your session has expired. Please login again.");
                logout();
            }
        }
        // Check the status is correct
        else {
            tutorialInfo_data = data;
        }
    },
    error: function(data){
        DEBUG && console.log("[FAIL] Request failed.");
        failed = true;

        // If request failed, display message
        alert("Sorry, something went wrong.\n\nPlease try again later.");

    },
    complete: function(){
        hideModal();
        busy=false;
    }
})

0 个答案:

没有答案