Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ajaxComplete, XMLHttpRequest is undefined

I have a global ajaxComplete handler:

 $('body').ajaxComplete(function (event, request, settings) {           
        if (request.getResponseHeader('REQUIRES_AUTH') === '1') {
            alert("unauthorized");                
        };
    });

The problem in that the request always in undefined, is filled only event.
Can you explain me why?

Example of ajax request:

$.ajax({
        cache: false,
        data: "GET",
        url: url,
        success: function (content) {           
            $('#modal').html(content);
            $('#modal').modal();           
        }
    });

UPDATE: From the API docs (Thanks to Austin Mullins):
As of jQuery 1.8, however, the .ajaxComplete() method should only be attached to document.

I have change my code to this:

$(document).ajaxComplete(function (event, request, settings) {            
        if (request.getResponseHeader('REQUIRES_AUTH') === '1') {
            alert("unauthorized");               
        };
    });

But now I get the error:

TypeError: document.createDocumentFragment is not a function    
safeFrag = document.createDocumentFragment(); (jquery-1.9.0.js (line 5800))

Browser is Firefox 19.0.2

SOLUTION: The problem was in the Jquery version 1.9.0. I have updated to 1.9.1 and the error is gone. Thanks to Boaz.

like image 734
user348173 Avatar asked Mar 13 '13 04:03

user348173


1 Answers

Following your edits, it seems you're using jQuery 1.9.0. There were several AJAX-related bugfixes in jQuery 1.9.1. Try using the latest jQuery release.

like image 114
Boaz Avatar answered Oct 04 '22 01:10

Boaz