Skip to main content

Bug Tracker

Side navigation

#8510 closed enhancement (fixed)

Opened March 12, 2011 03:23PM UTC

Closed June 16, 2011 04:26AM UTC

Last modified March 14, 2012 05:39PM UTC

JSONP cross domain requests with ajax (info in docs)

Reported by: bosak.tomas@gmail.com Owned by: bosak.tomas@gmail.com
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).

Attachments (0)
Change History (8)

Changed March 30, 2011 05:47PM UTC by dmethvin comment:1

component: unfiledajax
owner: → bosak.tomas@gmail.com
status: newpending

Can you post some more information about when this occurs?

Changed March 31, 2011 10:09AM UTC by yojimbo87 comment:2

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).

Changed March 31, 2011 03:46PM UTC by timmywil comment:3

keywords: → needsdocs
resolution: → wontfix
status: pendingclosed

Thank you! The docs will be updated accordingly.

Changed April 08, 2011 02:48PM UTC by anonymous comment:4

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'.

Changed April 09, 2011 10:12AM UTC by yojimbo87 comment:5

Replying to [comment:4 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.

Changed June 16, 2011 04:25AM UTC by addyosmani comment:6

resolution: wontfix
status: closedreopened

Changed June 16, 2011 04:26AM UTC by addyosmani comment:7

keywords: needsdocsneededdocs
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/

Changed December 08, 2011 12:18AM UTC by jon_wu comment:8

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/