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.
TypeError: document.createDocumentFragment is not a function
– Transverse$(document).ajaxComplete()
. – Managerialconsole.log(arguments)
and check the console – Pleuropneumoniasuccess
handler is not executed either? – Peakedsuccess
is executed. I meanajaxComplete
handler not executed at all. – Transverse.getResponseHeader()
method of thexhr
object returned to thesuccess
object? – Peakedsuccess
. all fine - status 200.getResponseHeader
works also. – Transverse1.9.0
. There were several AJAX-related bugfixes in jQuery1.9.1
. Try using the latest jQuery release, just to rule this out as the cause. – Peaked