Bug Tracker

Modify

Ticket #8510 (closed enhancement: fixed)

Opened 2 years ago

Last modified 15 months ago

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:
Blocking: Blocked by:

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

comment:1 Changed 2 years ago by dmethvin

  • Owner set to bosak.tomas@…
  • Status changed from new to pending
  • Component changed from unfiled to ajax

Can you post some more information about when this occurs?

comment:2 Changed 2 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 2 years ago by timmywil

  • Keywords needsdocs added
  • Status changed from pending to closed
  • Resolution set to wontfix

Thank you! The docs will be updated accordingly.

comment:4 follow-up: ↓ 5 Changed 2 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 2 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 2 years ago by addyosmani

  • Status changed from closed to reopened
  • Resolution wontfix deleted

comment:7 Changed 2 years ago by addyosmani

  • Keywords neededdocs added; needsdocs removed
  • Status changed from reopened to closed
  • Resolution set to fixed

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 19 months 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/

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.