AJAX事件处理程序 - beforeSend,失败并完成

时间:2014-04-29 16:26:20

标签: jquery ajax asp.net-mvc-3

我想在开始时附上一个"" AJAX调用的处理程序,但我正在

TypeError:request.beforeSend不是函数

就我在JQuery docs site上所读到的内容而言,以下内容应该有效,但唉,有些事情是困难的。谢谢你看

(使用JQuery 1.10.2)

  //Init the AJAX request and send
            var request = $.ajax({
                type: "POST",
                traditional: true,
                dataType: "html",
                url: "/NewClubOpeningTool/DeleteSelectedEmails/",
                data: { delete : checkedValues,clubId:"@Model.NewClub_Id" },
                cache: true
            });

            request.beforeSend(function() {

                $("#loading-area").show();

            });


            request.done(function (payload) {

            $("#loading-area").hide();
                //Do stuff ...

            });


            request.fail(function (jqXHR, textStatus) {

                 $("#loading-area").hide();
                //Do stuff...
            });

1 个答案:

答案 0 :(得分:3)

尝试

var request = $.ajax({
                type: "POST",
                traditional: true,
                dataType: "html",
                url: "/NewClubOpeningTool/DeleteSelectedEmails/",
                data: { delete : checkedValues,clubId:"@Model.NewClub_Id" },
                cache: true,
                beforeSend : function() {
                              $("#loading-area").show()
                             }
                });