5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JSONPとClosure Libraryのgoog.net.Jsonpのまとめ

Last updated at Posted at 2012-03-15

私がhtml5jにJSONPとClosure Libraryのgoog.net.Jsonpについて質問したスレッドのまとめです。
元スレ:http://goo.gl/ngnNj

JSONPが生まれた経緯とクロスドメインについて

JSONPについては、オリジナルドメインであればXHRで簡単にできることを、クロスドメインでどうするか?という問題を「 関数でpaddingしたJSONソース(テキストデータ)なら、SCRIPT要素で簡単に変数に格納できる!」という驚きがあり、広く使われるようになったと記憶しています。

JSONPライブラリを使う目的について

Jsonpライブラリを使う目的は、「JSONデータ」を読む事ですね。
機能面では仰るとおり、「ユーザーの訪問時の体感的なレスポンスを向上させる」ものですが、今のブラウザなら、技術的にはXHR2を使うことも可能なわけで。

JSONPについて

index.html
<script>
function myfunc(arg){
alert(arg);
}
</script>

と書いておいて、

other.js
myfunc('hello');

という1行を書いておいたファイルを

loading.html
<script src="other.js"></script>

として読み込むと、myfunc()が実行されるのと同じです。

goog.net.Jsonpについて

コールバック関数は第二引数に指定できます。
http://closure-library.googlecode.com/svn/docs/class_goog_net_Jsonp.html

jsonp.js
goog.net.Jsonp(url, 'callback');
//としておくと、
function callback(arg){
alert(arg);
}

と、あらかじめ作っておいた関数が実行されます。

JSONPしたあとの要素について

JSONPした後、使った

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?