Bug Tracker

Ticket #10256 (closed bug: invalid)

Opened 3 years ago

Last modified 3 years ago

Cross domain requests using jsonp

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

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"})

Change History

comment:1 Changed 3 years ago by stanislav

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

comment:2 Changed 3 years ago by rwaldron

  • Owner set to stanislav
  • Priority changed from undecided to low
  • Status changed from new to pending
  • Component changed from unfiled to ajax

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.

comment:3 Changed 3 years ago by stanislav

  • Status changed from pending to new

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

comment:4 Changed 3 years ago by rwaldron

  • Status changed from new to pending

Please provide a reduced test case

comment:5 Changed 3 years ago by stanislav

  • Status changed from pending to new

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'

comment:6 Changed 3 years ago by ajpiano

  • Status changed from new to closed
  • Resolution set to invalid

From  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.'''
Version 0, edited 3 years ago by ajpiano (next)

comment:7 Changed 3 years ago by stanislav

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

Note: See TracTickets for help on using tickets.