Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Nononono. No. Just please; no. That is not JSONP, it is javascript that executes a function with an object as its parameter that contains more javascript. Aaah!</p> <p>This is JSON because it's just one object:</p> <pre><code>{ 'one': 1, 'two': 2, 'three':3 } </code></pre> <p>This is JSONP because it's just one object passed through a function; if you go to <code>http://somesite/get_some_object?jsonp=grab</code>, the server will return:</p> <pre><code>grab({ 'one': 1, 'two': 2, 'three':3 }); </code></pre> <p>This is not JSON at all. It's just Javascript:</p> <pre><code>alert("hello"); </code></pre> <p>And this? Javascript code stored inside a string (ouch!) inside an object passed to a function that should evaluate the string (but it might or might not):</p> <pre><code>grab({"body": "alert(\"Hello!\");\n"}); </code></pre> <p>Look at all those semicolons and backslashes! I get nightmares from this kind of stuff. It's like a badly written Lisp macro because it's much more complicated than it needs to (and should!) be. Instead, define a function called <code>grab</code> in your code:</p> <pre><code>function grab(message) { alert(message.body); } </code></pre> <p>and then use JSONP to have the server return:</p> <pre><code>grab({body: "Hello!"}); </code></pre> <p>Don't let the server decide how to run your web page Instead, let your <em>web page</em> decide how to run the web page and just have the server fill in the blanks.</p> <p>As for an online service that does this? I don't know of any, sorry</p>
 

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