开发者

Ajax.ActionLink() and $.ajaxPrefilter() don't play nice

开发者 https://www.devze.com 2023-03-27 03:22 出处:网络
I\'m trying to implement a global ajax handler in my MVC app. I\'m using this code $.ajaxPrefilter(function (options, originalOptions, jqXHR) {

I'm trying to implement a global ajax handler in my MVC app. I'm using this code

    $.ajaxPrefilter(function (options, originalOptions, jqXHR) {
            jq开发者_开发技巧XHR.success(function (data) {
                console.log(this.url);
            });
    });

This generally works fine with all of my ajax request, except when I use Ajax.ActionLink() helper in MVC. the response is just ignored. I tried to look at both requests and responses and they seem to be pretty much the same.

are there any changes I need to make to make sure the Ajax.ActionLink() behaves like other Ajax requests?


In MVC3 you can use unobtrusive-ajax and the ajaxPrefilter will work since it uses jQuery to perform the underlying AJAX calls.

Some info on MVC3 and Unobtrusive AJAX: http://bradwilson.typepad.com/blog/2010/10/mvc3-unobtrusive-ajax.html

And the NUGET package: http://nuget.org/packages/jQuery.Ajax.Unobtrusive

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号