Are there reasons to not use JSONP for AJA ~ X requests?

If you are building an AJA~Xy application, are there any flaws in using JSONP requests / responses even if you are not planning on which cross-domain or cross-domain requests?

The only thing I can think of is that there are a couple extra bytes for the callback shell ...

Edit:

I found this, which also suggests security and error handling as potential problems ...

There is no error handling. script injection either works or not. If an error occurred during injection , it will go to the page, and, except for the error handler in the wide window (bad, bad, very bad), you need to make sure that the return value is valid on the server side .

I don’t think error handling is a big problem ... most of us use the library to generate JSON ... the correctness of my answer does not matter for this question.

and safety:

There are documents on the Internet that can help, but as a quick check, I would check the referrer in the script on the server side .

this seems like a potential problem with any type of answer ... of course, there is nothing unique to JSONP in security ...?

+6
json javascript jsonp ajax
source share
4 answers

Downside? It is quite limited - you run the "GET" request and return the executed script. You do not get error handling if your server throws an error, so you need to also wrap all errors in JSON as well. You cannot cancel or retry the request. You are at the mercy of various opinions of the authors of the browser about the "correct" behavior for dynamically generated <script> tags. Debugging is a bit more complicated.

However, I used it sometimes and did not suffer. YMMV.

+9
source share

Getting errors when jsonp call fails is possible.

http://code.google.com/p/jquery-jsonp/

Hope this helps.

+5
source share

I would say that the biggest limitation could be the extra overhead for the browser to display the script tag for the server call. Plus, JSONP is really considered AJAX since it doesn't actually use an XMLHttpRequest object?

+2
source share

Here is another bit that you can consider using JSONP .. possible memory leaks.

http://neil.fraser.name/news/2009/07/27/

0
source share

All Articles