开发者

ASP.NET MVC 3 - enabled unobtrusive javascript, ajaxComplete fires once and never again

Before unobtrusive javascript, I handled ajax complete events with the following register:

Sys.Net.WebRequestManager.add_completedRequest(myHandler);

This event handler will fire every time an ajax request is complete. I also have an ajaxComplete event bind in $(document).ready(), to handle ajax calls exclusively through jQuery:

$.ajaxComplete(function (e, xhr, settings) {
    myHandler(xhr)
});

Which also 开发者_StackOverflow社区works great. But I get a different behavior when I enabled unobstrusive javascript in ASP.NET MVC 3. It fires the first time when the first ajax call is complete, but on subsequent ajax requests, ajaxComplete event never fires again.

Now, I know about that you need to call $.validate.unobtrusive.parse() to rebuild the validation after the elements in the form updated via partial postback. Is there something similar that I need to do to make sure that ajaxComplete can fire again on subsequent requests? I cannot find the documentation on this.


FYI: I have included all the jquery*.js libs to support unobtrusive javascript. I also have the MicrosoftMvc*.js libs included to support legacy code in the project. I was hoping to convert everything over until I ran into this problem.


You need to actually attach ajaxComplete to an element I thought?

$('.info').ajaxComplete(function() {
   var info = $(this);
   info.html('Success!');
});

You should only need to attach ajaxComplete to an element once in its lifetime.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜