jquery ajax loader

Odi*_*aeb 1 ajax jquery

我有这样的脚本:

    $("#addk").bind("click", function(event){
        //alert("here!");
        $("#loader-overlay").show();
        $.ajax({
            'async':"False",
            'type': "POST",
            'url': "http://url/feedback/",
            'data': $("#form").serialize(), 
            'success': function(msg){
                $("#errors").html(msg);
                },
            'error' : function(){
                $("#errors").html('<p>fail</p>');
            }
        });
        $("#loader-overlay").hide();
        //return false;
    });
Run Code Online (Sandbox Code Playgroud)

由于某种原因,即使ajax运行几秒钟,装载程序屏幕也不会出现.如果我写

$("#loader-overlay").show();
Run Code Online (Sandbox Code Playgroud)

进入控制台,然后它工作得很好.

它可能非常简单,我只是不能指责.

艾伦

Eli*_*Eli 8

你可能应该在ajax请求中显示和隐藏加载作为回调.查看:http://api.jquery.com/jQuery.ajax/#callback-functions

所以,你可能会这样做:

$.ajax({..., beforeSend: function(){ /* show the loading thing */ },
    complete: function(){ /* hide the loader */ }});
Run Code Online (Sandbox Code Playgroud)