Ticket #5507 (closed bug: duplicate)
Ajax Fires "Complete" Event Twice (JSONP)
| Reported by: | Wardrop | Owned by: | |
|---|---|---|---|
| Priority: | major | Milestone: | 1.4 |
| Component: | ajax | Version: | 1.3.2 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
When using $.ajax() for JSONP requests, the "complete" event is fired twice if the JSONP request is from and to the same domain.
You could argue that JSONP shouldn't be used for same-domain JSON requests, but there are circumstances where this does occur for whatever reason, such as in a testing environment where the JSONP resides under the same domain (which may be 'localhost').
This isn't a hard one to reproduce, but here's some sample code anyway...
<script src="jquery-1.3.2.js"></script> <script>
$.ajax({ type : "GET",
url : <insert url here>, async : false, dataType : "json", complete : function () { alert('complete'); }
});
</script>
Simply replace <insert url here> with a JSONP URL from the same domain the script is run from, and then repeat the test with a JSONP URL from another domain.
Change History
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Duplicate of #5383.