2016年4月16日土曜日
d3.jsonを一時的にハードコードしたデータでテストしたい時
こういうAjaxでのリクエストを、
d3.json("/test/this/url", function(json) {
// ToDo: ------> Write something here..
}
こういう感じで変えると、バックエンドがない場合でもテストできる。
var testData = '{test:[1,2,3]}';
var json = JSON.parse( testData );
http://stackoverflow.com/questions/10934853/d3-js-loading-json-without-a-http-get
ラベル:
AJAX,
d3,
JavaScript,
JSON
2013年11月23日土曜日
jQueryでAjaxを使ったDataTableでちょっとハマったとこ
jQueryのDatableのプラグインで、Ajaxを使ってサーバーサイドからデータを取るページを作るのに若干ハマったとこをメモ書き。
ページでテーブルが表示されてから、何かのアクションを起こしてテーブルをサーバーサイドのデータで再描画する時、sEchoというパラメータに注意。あまり注意してなかったので、適当に1と設定していたのですが、これは描画リクエストがある度に更新してやらないと、クライアントサイドで再描画が起こらない。(キャッシュしてるのかな?)
という事なので、バックエンドではインクリメントをして返してやると、ちゃんとテーブルを描画してくれました。
string | sEcho | An unaltered copy of sEcho sent from the client side. This parameter will change with each draw (it is basically a draw count) - so it is important that this is implemented. Note that it strongly recommended for security reasons that you 'cast' this parameter to an integer in order to prevent Cross Site Scripting (XSS) attacks. |
ラベル:
AJAX,
DataTables,
jQuery
2013年11月16日土曜日
jQueryとAjaxを使ってフォームのデータを送信する時、たくさんのエレメントがあると面倒くさいのでserialize()を使う。
<form id="someForm">...</form>
<script>
$.ajax({
url: 'someurl',
type: 'post',
data: $('#someForm').serialize()
}) ;
</script>
こんな感じ。
http://stackoverflow.com/questions/5004233/capture-all-of-the-forms-data-and-submit-it-to-a-php-script-jquery-ajax-post
<script>
$.ajax({
url: 'someurl',
type: 'post',
data: $('#someForm').serialize()
}) ;
</script>
こんな感じ。
http://stackoverflow.com/questions/5004233/capture-all-of-the-forms-data-and-submit-it-to-a-php-script-jquery-ajax-post
ラベル:
AJAX,
JavaScript,
jQuery
2013年10月22日火曜日
jQueryでAjaxを使ってJSONを扱うには
$.ajax({
url: "someUrl", // -----------------------> リクエストするURL
dataType: "json", // -----------------------> JSONがサーバーから返ってくる事を想定
success: function(response) {
// -----------------------> JSONをresponse.person.nameなどのような形で操作する
}
});
登録:
投稿 (Atom)