Skip to content

jsonp is called instead of json in cross domain requests #329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

ubershmekel
Copy link
Contributor

This was surprising to me and I'm still not sure how to handle cross-domain jsonp 404 responses.

@JonathanThiyagarajan
Copy link

If you are trying to post a data. you could not do it So, You Can use get method in regards with the cross domain, Trying using crossdomain:true, in your ajax call

@ubershmekel
Copy link
Contributor Author

The jsonp request in question happens on my site for example here http://www.redditp.com/r/qwer/awwasdfasdfasdfa/ note that I do give an error after a timeout though the 404 arrives before the alert pops up. Will crossdomain:true help me catch and handle the 404 event?

@JonathanThiyagarajan
Copy link

U can Very handle the 404 Event.

@gnarf
Copy link
Member

gnarf commented Nov 21, 2013

So long as you are in here, could you separate each of those <li> onto it's own line? It would make this much easier to review. I can tell you from a quick read that you'll want to remove the ...

Also, have you signed the CLA? http://contribute.jquery.org/CLA/

@ubershmekel
Copy link
Contributor Author

Fixed that and just signed. I'll verify the 404's catchable with crossdomain:true hopefully in ~10 hours.

@kswedberg
Copy link
Member

I think this is too vague/incomplete, and I'm not quite sure how to fix it. In which cases does it force a "jsonp request"? Did you verify the catchable 404s? You can make an xhr post or get using CORS and it won't try to use jsonp. You would need to set the xhrFields option:

xhrFields: {
    withCredentials: true
}

<li>"json": Evaluates the response as JSON and returns a JavaScript object. Cross-domain requests may invoke "jsonp" unless explicitly "jsonp" is set to false.. The JSON data is parsed in a strict manner; any malformed JSON is rejected and a parse error is thrown. As of jQuery 1.9, an empty response is also rejected; the server should return a response of <code>null</code> or <code>{}</code> instead. (See <a href="http://json.org/">json.org</a> for more information on proper JSON formatting.)</li>
<li>"jsonp": Loads in a JSON block using <a href="http://bob.pythonmac.org/archives/2005/12/05/remote-json-jsonp/">JSONP</a>. Adds an extra "?callback=?" to the end of your URL to specify the callback. Disables caching by appending a query string parameter, "_=[TIMESTAMP]", to the URL unless the <code>cache</code> option is set to <code>true</code>.</li>
<li>"text": A plain text string.</li><li>multiple, space-separated values: <strong>As of jQuery 1.5</strong>, jQuery can convert a dataType from what it received in the Content-Type header to what you require. For example, if you want a text response to be treated as XML, use "text xml" for the dataType. You can also make a JSONP request, have it received as text, and interpreted by jQuery as XML: "jsonp text xml." Similarly, a shorthand string such as "jsonp xml" will first attempt to convert from jsonp to xml, and, failing that, convert from jsonp to text, and then from text to xml.
</li>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be on the previous line.

@gnarf
Copy link
Member

gnarf commented Dec 22, 2014

@ubershmekel - do you have any updates on this issue specifically for @kswedberg's comment? It seems like one of those awkward edge cases we don't want to document unless we can clearly explain the situation it occurs in.

@arthurvr
Copy link
Member

arthurvr commented Mar 7, 2015

@ubershmekel This PR needs some updates. See comments above. It would be nice if you could do them?

@ubershmekel
Copy link
Contributor Author

Fixed the complaints and fixed the merge. From my testing crossdomain does not help detect the 404. The 404 being undetectable may be a browser security feature.

@arthurvr
Copy link
Member

arthurvr commented Apr 9, 2015

Thanks @ubershmekel. What do we think @gnarf @kswedberg?

@dmethvin
Copy link
Member

dmethvin commented Apr 9, 2015

I definitely like this formatting better. For this:

Cross-domain requests may invoke "jsonp" unless explicitly "jsonp" is set to false.

I'd change it to something like:

Cross-domain "json" requests are converted to "jsonp" unless the request includes jsonp: false in its request options.

@arthurvr
Copy link
Member

ping @ubershmekel

@ubershmekel
Copy link
Contributor Author

Sorry guys, I was abroad for a few weeks. It's a bit of a pain that every time I come back to this tiny change the pull request has merge conflicts.

I do like the proposed wording. If I fix it per @dmethvin would that be the final iteration?

@arthurvr
Copy link
Member

It's a bit of a pain that every time I come back to this tiny change the pull request has merge conflicts.

For now feel free to not care about merge conflicts. I can take care of them while merging.

Relevant li's have newlines between them now.
@ubershmekel
Copy link
Contributor Author

Rebased with the new wording.

@ubershmekel
Copy link
Contributor Author

Ping @dmethvin @arthurvr before the next conflict.

@dmethvin
Copy link
Member

Whoa, sorry this got buried. LGTM!

<ul><li>"xml": Returns a XML document that can be processed via jQuery.</li><li>"html": Returns HTML as plain text; included script tags are evaluated when inserted in the DOM.</li><li>"script": Evaluates the response as JavaScript and returns it as plain text. Disables caching by appending a query string parameter, "_=[TIMESTAMP]", to the URL unless the <code>cache</code> option is set to <code>true</code>. <strong>Note:</strong> This will turn POSTs into GETs for remote-domain requests. </li><li>"json": Evaluates the response as JSON and returns a JavaScript object. The JSON data is parsed in a strict manner; any malformed JSON is rejected and a parse error is thrown. As of jQuery 1.9, an empty response is also rejected; the server should return a response of <code>null</code> or <code>{}</code> instead. (See <a href="http://json.org/">json.org</a> for more information on proper JSON formatting.)</li><li>"jsonp": Loads in a JSON block using <a href="http://bob.ippoli.to/archives/2005/12/05/remote-json-jsonp/">JSONP</a>. Adds an extra "?callback=?" to the end of your URL to specify the callback. Disables caching by appending a query string parameter, "_=[TIMESTAMP]", to the URL unless the <code>cache</code> option is set to <code>true</code>.</li><li>"text": A plain text string.</li><li>multiple, space-separated values: <strong>As of jQuery 1.5</strong>, jQuery can convert a dataType from what it received in the Content-Type header to what you require. For example, if you want a text response to be treated as XML, use "text xml" for the dataType. You can also make a JSONP request, have it received as text, and interpreted by jQuery as XML: "jsonp text xml." Similarly, a shorthand string such as "jsonp xml" will first attempt to convert from jsonp to xml, and, failing that, convert from jsonp to text, and then from text to xml.
</li></ul>
<ul>
<li>"xml": Returns a XML document that can be processed via jQuery.</li>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"xml"

I wonder if these shouldn't be in <code> elements. For the rest this LGTM!

@arthurvr
Copy link
Member

I'm going to make that trivial change myself and land this one. Thanks for your hard work, @ubershmekel, and sorry for it taking too long :)

@arthurvr arthurvr closed this in be83880 May 24, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

8 participants