Skip to content
This repository was archived by the owner on Nov 1, 2017. It is now read-only.

Commit 8d06fec

Browse files
committed
Merge pull request #87 from github/fix-shiny-memes
Update JSONP docs to mention protection against hijacking
2 parents 95c62bd + 1215f7d commit 8d06fec

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

content/v3.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ plus the relevant HTTP Header information.
517517
<pre class="terminal">
518518
$ curl https://api.github.com?callback=foo
519519

520-
foo({
520+
/**/foo({
521521
"meta": {
522522
"status": 200,
523523
"X-RateLimit-Limit": "5000",
@@ -533,14 +533,30 @@ foo({
533533
})
534534
</pre>
535535

536-
You can write a JavaScript handler to process the callback like this:
536+
You can write a JavaScript handler to process the callback. Here's a minimal example you can try out:
537537

538-
<pre><code class="language-javascript">function foo(response) {
538+
<pre><code class="language-html">&lt;html>
539+
&lt;head>
540+
&lt;script type="text/javascript">
541+
function foo(response) {
539542
var meta = response.meta
540543
var data = response.data
541544
console.log(meta)
542545
console.log(data)
543-
}</code></pre>
546+
}
547+
548+
var script = document.createElement('script');
549+
script.src = 'https://api.github.com?callback=foo'
550+
551+
document.getElementsByTagName('head')[0].appendChild(script);
552+
&lt;/script>
553+
&lt;/head>
554+
555+
&lt;body>
556+
&lt;p>Open up your browser's console.&lt;/p>
557+
&lt;/body>
558+
559+
&lt;/html></code></pre>
544560

545561
All of the headers are the same String value as the HTTP Headers with one
546562
notable exception: Link. Link headers are pre-parsed for you and come

0 commit comments

Comments
 (0)