Skip to main content

Bug Tracker

Side navigation

#10256 closed bug (invalid)

Opened September 12, 2011 04:55PM UTC

Closed September 21, 2011 09:39AM UTC

Last modified September 21, 2011 09:41AM UTC

Cross domain requests using jsonp

Reported by: stanislav Owned by: stanislav
Priority: low Milestone: None
Component: ajax Version: 1.6.3
Keywords: Cc:
Blocked by: Blocking:
Description

When you perform a cross-domain jsonp request using jquery and if the server returns the jsonp response using status code != 200 you have the following:

1. the registered error callback function tells you that status code is 200

2. jquery is unable to parse jsonp - parseerror

The bellow http responses demonstrate the mentioned behavior.

The first one is processed correctly instead of the second one.

HTTP/1.1 200 OK

Cache-Control: private

Content-Length: 211

Content-Type: application/json

Server: Microsoft-IIS/7.5

X-AspNet-Version: 4.0.30319

X-Powered-By: ASP.NET

Date: Mon, 12 Sep 2011 15:27:42 GMT

jQuery16306215030491174232_1315841261014({"initData":"bla-bla"})

HTTP/1.1 400 Bad Request

Cache-Control: private

Content-Length: 169

Content-Type: application/json

Server: Microsoft-IIS/7.5

X-AspNet-Version: 4.0.30319

X-Powered-By: ASP.NET

Date: Mon, 12 Sep 2011 16:49:55 GMT

jQuery16309673461931202953_1315846180861({"error":"Bla-bla"})

Attachments (0)
Change History (7)

Changed September 12, 2011 05:24PM UTC by stanislav comment:1

I suppose that the main issue is that jquery doesn't process jsonp correctly in the case of StatusCode != 200.

Changed September 12, 2011 06:00PM UTC by rwaldron comment:2

component: unfiledajax
owner: → stanislav
priority: undecidedlow
status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a complete reduced test case on jsFiddle to help us assess your ticket!

Additionally, be sure to test against the jQuery Edge version to ensure the issue still exists. To get you started, use this boilerplate: http://jsfiddle.net/FrKyN/

Open the link and click to "Fork" (in the top menu) to get started.

Changed September 12, 2011 07:51PM UTC by stanislav comment:3

status: pendingnew

I've simply forgot to add: I've got this behavior in IE9 (haven't tested in other browsers yet)

Changed September 19, 2011 04:10PM UTC by rwaldron comment:4

status: newpending

Please provide a reduced test case

Changed September 21, 2011 08:38AM UTC by stanislav comment:5

status: pendingnew

Hello,

The test could be found here http://jsfiddle.net/F7D7U/6/

Here is some explanation http://clip2net.com/s/1bJGO

I'm not really sure that it is an issue at all, but I haven't found any documentation which tells that we can't use status codes <> 200 within jasonp requests.

In IE 9 it invokes error callback with textStatus = 'parsererror'

Changed September 21, 2011 09:39AM UTC by ajpiano comment:6

_comment0: From [http://api.jquery.com/jQuery.ajax/ the jQuery.ajax docs] \ \ {{{ \ error(jqXHR, textStatus, errorThrown)Function \ A function to be called if the request fails. ....'''Note: This handler is not called for cross-domain script and JSONP requests.''' \ }}} \ 1316597999612264
_comment1: From [http://api.jquery.com/jQuery.ajax/ the jQuery.ajax docs] \ \ {{{ \ error(jqXHR, textStatus, errorThrown)Function \ A function to be called if the request fails. ...'Note: This handler is not called for cross-domain script and JSONP requests. \ }}} \ 1316598028033349
resolution: → invalid
status: newclosed

From the jQuery.ajax docs

error(jqXHR, textStatus, errorThrown)Function
A function to be called if the request fails
[snip]
Note: This handler is not called for cross-domain script and JSONP requests.

Changed September 21, 2011 09:41AM UTC by stanislav comment:7

IE9 calls it anyway. BTW, is there any possible way to get the response message?