Home › JavaScript Tutorial › JS JSONP
JS JSONP
An old cross-domain trick.
JSONP loads a script whose reply calls your function with the data. It is insecure and replaced by CORS with fetch. This demo fakes the server reply locally.
Example code
<pre id='o'></pre>
<script>
function handle(data){o.textContent='Callback got: '+JSON.stringify(data);}
// a server would reply with this text as a script:
handle({user:'Ada',id:7});
</script>