2

When Unobtrusive ajax performs an ajax call, it doesn't appear to call the global jquery ajax events. Here is an example of my attempt to handle the event.

$(document).ajaxComplete(function () { alert('test'); });

The event works fine if I make ajax calls like this:

$.ajax({
    url: "/myurl",
    type: 'GET',
    success: function (data) { //do something }
});

Any idea how to set up a global handle for all ajax complete events, regardless of their source? Or how to handle global events for Unobtrusive Ajax?

Nathan A
  • 11,059
  • 4
  • 47
  • 63
  • Sorry, I deleted my previous answer because I realized that I did not understand what Unobtrusive is. After reading a few posts about it I see now that it does override these prefiltering options. – crickkills Mar 14 '14 at 14:46
  • Did you find an answer for this? Experiencing something similar after upgrading to the latest unobtrusive ajax with MVC4 and jQuery 1.11.1. – awright May 21 '14 at 10:45

1 Answers1

1

We were running into the same problem. For some reason .ajaxComplete was not working with unobtrusive ajax. However, we did find that .ajaxStart and .ajaxStop were always being called.

Here's how we're using it to handle a spinner and re-parse the validation on dynamic content:

$(document).ajaxStart(function (event, jqxhr, settings) {
        $("#ajax-spinner").show();
    });

    $(document).ajaxStop(function (event, jqxhr, settings) {
        $("#ajax-spinner").hide();

        $("form").each(function () {
            var form = $(this);
            form.removeData('validator');
            form.removeData('unobtrusiveValidation');
            $.validator.unobtrusive.parse(form);
        });
    });
BlackjacketMack
  • 5,472
  • 28
  • 32