Possible jQuery 1.4.2 JSONP bug with executing complete handler twice
While debugging a plug-in tool that I have developed,
ajaxMonitor. I found that $.ajax with JSONP was executing the complete handler two times more than once
Here is the unit test written in QUnit to verify my results:
- test("jQuery.ajax() - JSONP, Local [validate completion count]", function() {
expect(3);
var otherHandlerCount = 0;
var completeCount = 0;
function validateCompleteCount(){
if ( otherHandlerCount == 1 ) {
if(completeCount !== 1) {
ok(false, 'the complete count was: ' + completeCount);
}
else {
ok(true, 'the complete count was: ' + completeCount);
}
start();
}
}
stop();
jQuery.ajax({
url: "data/jsonp.php",
dataType: "jsonp",
success: function(data){
ok( data.data, "JSON results returned (GET, no callback)" );
otherHandlerCount++;
},
error: function(data){
ok( false, "Ajax error JSON (GET, no callback)" );
otherHandlerCount++;
}
,complete: function() {
completeCount++;
validateCompleteCount();
}
});
});
Here is a screen shot of the results.
BTW, Having so many ajax call in one test is cumbersome and is really a code smell from my perspective.
Thanks for any assistance in fixing this problem.
PS: My repository for the ajaxMonitor plug-in.