简体   繁体   English

ajaxStart在Ajax Post上不起作用

[英]ajaxStart does not work on Ajax Post

I have ajaxStart event that is working fine for ajax loads. 我有一个ajaxStart事件,对于ajax加载工作正常。 But when I do a POST is not working at all. 但是当我执行POST时根本无法正常工作。

Here the code that is always render per all pages. 在这里,始终按所有页面呈现的代码。

 $(document).ajaxComplete(function () {
        hideIcon();
        if (stepState !== '' && stepState !== CONSTANTS.DISABLED_FORM) {
            enableElement();
        }
    });
    $(document).ajaxStart(function () {
        showIcon();
        disableElement();
    });

And here my post. 这是我的帖子

     var sendRequest = function (url, data) {
    $.ajaxPrefilter(function( options ) {
        options.global = true;
    });
    $.ajax({
        dataType: "json",
        method: "POST",
        url: url,
        data: data,
        success: function (data) {
            applicationAlerts.showStatus(data);
            loadDocumentGroup();
        }
    });
};

I follow this tickets here https://forum.jquery.com/topic/ajaxstart-is-not-working , but in my case does not work. 我在这里https://forum.jquery.com/topic/ajaxstart-is-not-working上遵循此票证,但是在我的情况下不起作用。

I´m using JQuery 1.11 我正在使用JQuery 1.11

Any suggestion?. 有什么建议吗? Thanks! 谢谢!

I think you made mistake in ajax function.Try to change like this 我认为您在ajax函数中犯了错误。尝试像这样更改

$.ajax({
        dataType: "json",
        type: "POST",
.....
});

There is no Parameter like method in ajax Request.You need to use type parameter to specify the type of Request.(GET OR POST) ajax Request中没有类似Parameter的method 。您需要使用type参数来指定Request的类型。(GET或POST)

Hope it will works!. 希望它能工作! Thanks 谢谢

If you are using jquery version 1.9 or later use: 如果您正在使用jQuery 1.9或更高版本,请使用:

method: "POST" 

or 要么

type: "POST"

if the version is below 1.9, only use: 如果版本低于1.9,请仅使用:

type: "POST"

For your reference 供您参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM