LoginSignup
17
25

More than 5 years have passed since last update.

【jQuery】$.getJSON()

Last updated at Posted at 2015-02-18

概要

jQuery.getJSON(url, [data], [handler])

Getメソッドで値を取得する。取得した値はオブジェクトとして扱われる。(ように見える。。)

$.get()をラップしたもので、以下と同等。

$.get(url, data, callback, "json");

JSONPまわりの話はのちほど。

パラメータ

  • $.getJSONのパラメータ

url:url
data:サーバへ送信するデータ。オブジェクトで設定。
callback:成功時のコールバック。$.ajax()のsuccessと同じ。

  • callbackの引数

data:サーバから返るJSONオブジェクト
status:リクエスト結果を表す文字列

$.getJSON(
  "test.php", //リクエストURL
  null,       //送信データ
  function(data, status) {
    // 通信成功時の処理
  }
);

参考:$.getJSON

サーバ側の処理:【Cake】Jsonを出力する処理

17
25
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
17
25