weixin_33733810 2016-10-05 02:19 采纳率: 0%
浏览 26

通过jQuery检测Ajax请求

I'm working with asp controls and I have some dropdownlist which in selection go back to the server and do some action ( via asp ajax ) what I'm l looking for is detecting via jquery when the ajax call is starting I've tried the following call :

  $.ajaxSetup({
                    beforeSend: function (jqXHR, settings) {
                        alert("ok");
                        return false;
                    }
                });

and

also  $(document).ajaxStart(function () {
                   alert("OK");
                });

but none of this worked

  • 写回答

3条回答 默认 最新

  • 零零乙 2016-10-05 02:32
    关注

    You can show your loader / waiting image in ajax request in this way.

    $('#loading-image').show();
    $.ajax({
          url: uri,
          cache: false,
          success: function(html){
            $('.info').append(html);
          },
          complete: function(){
            $('#loading-image').hide();
          }
    });
    

    If you want to bind global events like ajaxStart and ajaxStop.

    $("#loading").bind("ajaxStart", function(){
        $(this).show();
    }).bind("ajaxStop", function(){
        $(this).hide();
    });
    
    评论
编辑
预览

报告相同问题?