LoginSignup
3
3

More than 5 years have passed since last update.

jQuery.ajax() のダミーデータを素早く作る

Last updated at Posted at 2012-06-08

メリット

  • HTMLとJSだけで完結
  • マークアップの人がローカルファイルで作業できる
  • 本番コードの修正をしなくて良い (たぶん)

デメリット

  • ajax の beforeSend が設定してあると動かない
dummydata.js
$(function () { 
    // 返したいダミーデータ   var result = {"result": "some dummy data"};


    // ajaxメソッドパラメータのデフォルト値 $.ajaxSetup({       beforeSend: function(xhr) {

            // GET のパラメータを考慮して、前方一致         if( this.url.match(/^\/target_url.*/) ) {

                // Ajax 通信をキャンセル                xhr.abort();                
                // 結果を出力
                this.success(result, "success", xhr);           }       }   });});

beforeSend を使わない方法を模索中。。。

3
3
1

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
3
3