Take the 2-minute tour ×
Stack Apps is a question and answer site for apps, scripts, and development with the Stack Exchange API. It's 100% free, no registration required.

Conclusion: fast response by Kevin enables the JSONP functionality of the API to assume it's rightful description of awesome.

http://soapi.info/Code/JS/Stable/ErrorTest.htm


The JSONP functionality is great, but implementation differences between browsers severely cripple any efforts to respond to error conditions. In most browsers, a non 200 will not result in injection of the response text.

Notice that JQuery does not support error callbacks for JSONP. The only way to assume an error is to use a timeout.

See SOAPI-EXPLORE for an example. Input bogus params and submit - no return.

If, when JSONP is specified, the API would send the error json with a 200 we could receive the error and respond appropriately.

There is no way to reliably receive a JSONP result with an http status != 200, rendering the JSONP functionality of the API unreliable.

Demonstration

http://soapi.info/Code/JS/Stable/ErrorTest.htm

Results:

  • WebKit (Chrome, Safari): the browser passes the response and we can examine the jsob to determine whether it is an error.

  • IE, Opera, Firefox: no result. dead. only option is to implement a timeout.

UPDATE:

WebKit only lets the 500 error through. 404 and the 4000's are all swallowed by the browser, making the case for a 200 status for jsonp errors.

share|improve this question
1  
I agree - especially because my JavaScript wrapper uses jsonp too. –  Nathan Osman Jun 10 '10 at 5:32

1 Answer 1

up vote 2 down vote accepted

Done.

Compare:
http://api.stackoverflow.com/0.8/errors/4002
and
http://api.stackoverflow.com/0.8/errors/4002?jsonp=wrapperFunc

share|improve this answer
1  
++++ thanks for the quick response. I move kinda quick and when I get stuck i start pulling out hair. –  Sky Sanders Jun 10 '10 at 6:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .