[jQuery] 複数の data をサーバー(ashx)に渡す

以下のように渡してしまうと、code1 しか渡すことができず、code2 を参照すると null 参照となってしまう。
$.ajax({
 type: "POST",
 url: "http://exsample.com/code.ashx",
 data: { "code1": $("#txtCode1").val() },
 data: { "code2": $("#txtCode2").val() },
 dataType: "json",
 cache: true,
 success: function (result) {
  hoge(result);
 },
 error: function (obj, err) {
 }
});
以下のように Json の変数に整形すると値を渡すことができる。
受け取り側は HttpContext の Request で取得する。
var dat = { "code1": $("#txtCode1").val(), "code2": $("#txtCode2").val() };
$.ajax({
 type: "POST",
 url: "http://exsample.com/code.ashx",
 data: dat,
 dataType: "json",
 cache: true,
 success: function (result) {
  hoge(result);
 },
 error: function (obj, err) {
 }
});

このブログの人気の投稿

コピーした行の挿入が表示されない時はフィルタされていないかチェック

Excel で一部の図形だけ固定する