Bug Tracker

Opened 9 years ago

Closed 8 years ago

Last modified 8 years ago

#8510 closed enhancement (fixed)

JSONP cross domain requests with ajax (info in docs)

Reported by: bosak.tomas@… Owned by: bosak.tomas@…
Priority: undecided Milestone: 1.next
Component: ajax Version: 1.5.1
Keywords: neededdocs Cc:
Blocked by: Blocking:

Description

This is not a bug, but probable misleading information in documentation: jQuery.ajax() function

  • error(jqXHR, textStatus, errorThrown) callback handler

It's stated there that: Note: This handler is not called for cross-domain script and JSONP requests.

However after some testing (with jquery 1.5.1) it looks like error handler is now called when error happens during JSONP cross-domain ajax requests using this function. This behavior (which is stated in documentation) was true for previous versions of jquery (for example error handler isn't called with jqeury 1.4).

Change History (8)

comment:1 Changed 9 years ago by dmethvin

Component: unfiledajax
Owner: set to bosak.tomas@…
Status: newpending

Can you post some more information about when this occurs?

comment:2 Changed 9 years ago by yojimbo87

Sure. Here is code with jQuery 1.5.1 which will alert timeout error because 1 ms timeout is too small to process the request: http://jsfiddle.net/yojimbo87/5P84g/

And here is the same code with jQuery 1.4.4 which alerts success although it should also do the same thing (alert timeout error) as in first example: http://jsfiddle.net/yojimbo87/8vbgX/

Again this is not a jQuery bug, but an ajax documentation "issue" (error handler) which should be probably updated to reflect the current state which is: error handler is called also for JSONP requests (I haven't tried it with cross-domain scripts).

comment:3 Changed 9 years ago by timmywil

Keywords: needsdocs added
Resolution: wontfix
Status: pendingclosed

Thank you! The docs will be updated accordingly.

comment:4 Changed 9 years ago by anonymous

Cross domain jsonp requests do not seem to be working with $.ajax(). The error handler is not called when I am using dataType: 'jsonp', however this does work with dataType: 'xml'.

comment:5 in reply to:  4 Changed 9 years ago by yojimbo87

Replying to anonymous:

Cross domain jsonp requests do not seem to be working with $.ajax(). The error handler is not called when I am using dataType: 'jsonp', however this does work with dataType: 'xml'.

I just tried the same example with cross-domain JSONP data type request and error handler was fired when using jQuery 1.5.2 and not fired using jQuery 1.4.4.

comment:6 Changed 8 years ago by addyosmani

Resolution: wontfix
Status: closedreopened

comment:7 Changed 8 years ago by addyosmani

Keywords: neededdocs added; needsdocs removed
Resolution: fixed
Status: reopenedclosed

I've re-tested this to establish the version where the change was made and updated the docs to reflect it: http://api.jquery.com/jQuery.ajax/

comment:8 Changed 8 years ago by jon_wu

The docs are still misleading. The jQuery.ajax docs still say: "Note: This handler is not called for cross-domain script and JSONP requests."

The snippet that opened this issue shows that the handler is called actually called. I've noticed that it's called for at least timeout and parsererror.

In addition, the global error handler isn't called. This would be expected if the error callback passed to jQuery.ajax didn't fire but since it does, it's unexpected.

Examples: http://jsfiddle.net/pte5g/

Note: See TracTickets for help on using tickets.