0

daデータベースからデータを取得するWebメソッドにデータを送信する単純なjQueryAJAXメソッドがあります。番号を送信すると正常に動作しますが、パラメータを使用してデータを送信する方法がわかりません。

たとえば、このメソッドは正しく機能します。

function catchdata() {
     $.ajax({
         type: "POST",
         url: "rank.aspx/bringdata",
         data: "{lmt:16}",
         contentType: "application/json; charset=utf-8",
         dataType: "json",
         async: true,
         cache: false,
         success: function(ret){
             s = ret.d;
             dos(s, 0);
         },
         error: function(x,e){
             alert("error occur");
         } 
     });
}

しかし、以下のコードは機能せず、エラー関数が発生します。

function catchdata() {
     $.ajax({
         type: "POST",
         url: "rank.aspx/bringdata",
         data: {
             lmt:total
         },
         async: true,
         cache: false,
         success: function(ret){
             s = ret.d;
             dos(s, 0);
         },
         error: function(x,e){
             alert("error occur");
         }
     });
}
4

1 に答える 1

3

If the first example works fine, this should do the same with a parameter: (I assume total is defined as global variable elsewhere)

$.ajax({
     type: "POST",
     url: "rank.aspx/bringdata",
     data: "{lmt:" + total + "}",
     contentType: "application/json; charset=utf-8",
     dataType: "json",
     async: true,
     cache: false,
     success: function(ret){
         s = ret.d;
         dos(s, 0);
     },
     error: function(x,e){
         alert("error occur");
     } 
 });
于 2012-08-08T09:02:23.077 に答える