Test case for jQuery Ticket 3227
jsonp and the ajax callbacks
by jitter
HTML
<button id="check"> Uncalled callbacks </button>
JavaScript
function remove(val, arr) {
var index = jQuery.inArray(val, arr);
if (index > -1) {
var rest = arr.slice(index + 1 || arr.length);
arr.length = index;
arr.push.apply(arr, rest);
}
return arr;
}
var events = ["ajaxStart", "beforeSend", "ajaxSend", "dataFilter", "success", "ajaxSuccess", "error", "ajaxError", "complete", "ajaxComplete", "ajaxStop" ];
$("body").ajaxStart(function() { events = remove("ajaxStart", events); });
$("body").ajaxSend(function() { events = remove("ajaxSend", events); });
$("body").ajaxSuccess(function() { events = remove("ajaxSuccess", events); });
$("body").ajaxError(function() { events = remove("ajaxError", events); });
$("body").ajaxComplete(function() { events = remove("ajaxComplete", events); });
$("body").ajaxStop(function() { events = remove("ajaxStop", events); });
//yes this is actually remote jsonp request don't let the url fool you
$.ajax({
url: "http://jsfiddle.net/echo/jsonp/",
dataType: "jsonp",
data: { a: "b" },
success: function() { events = remove("success", events); },
beforeSend: function() { events = remove("beforeSend", events); },
complete: function() { events = remove("complete", events); },
dataFilter: function() { events = remove("dataFilter", events); }
});
$.ajax({
url: "http://example.com/fuu",
dataType: "jsonp",
error: function() { events = remove("error", events); }
});
$("#check").click(function() {
alert(events);
});