Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>For the record, as far as I can tell, you had two problems:</p> <ol> <li><p>You weren't passing a "jsonp" type specifier to your <code>$.get</code>, so it was using an ordinary XMLHttpRequest. However, your browser supported CORS (Cross-Origin Resource Sharing) to allow cross-domain XMLHttpRequest if the server OKed it. That's where the <code>Access-Control-Allow-Origin</code> header came in.</p></li> <li><p>I believe you mentioned you were running it from a file:// URL. There are two ways for CORS headers to signal that a cross-domain XHR is OK. One is to send <code>Access-Control-Allow-Origin: *</code> (which, if you were reaching Flickr via <code>$.get</code>, they must have been doing) while the other was to echo back the contents of the <code>Origin</code> header. However, <code>file://</code> URLs produce a null <code>Origin</code> which can't be authorized via echo-back.</p></li> </ol> <p>The first was solved in a roundabout way by Darin's suggestion to use <code>$.getJSON</code>. It does a little magic to change the request type from its default of "json" to "jsonp" if it sees the substring <code>callback=?</code> in the URL.</p> <p>That solved the second by no longer trying to perform a CORS request from a <code>file://</code> URL.</p> <p>To clarify for other people, here are the simple troubleshooting instructions:</p> <ol> <li>If you're trying to use JSONP, make sure one of the following is the case: <ul> <li>You're using <code>$.get</code> and set <a href="http://api.jquery.com/jQuery.get/" rel="noreferrer"><code>dataType</code></a> to <code>jsonp</code>.</li> <li>You're using <code>$.getJSON</code> and included <code>callback=?</code> in the URL.</li> </ul></li> <li>If you're trying to do a cross-domain XMLHttpRequest via CORS... <ol> <li>Make sure you're testing via <code>http://</code>. Scripts running via <code>file://</code> have limited support for CORS.</li> <li>Make sure the browser <a href="http://caniuse.com/cors" rel="noreferrer">actually supports CORS</a>. (Opera and Internet Explorer are late to the party)</li> </ol></li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload