Reputation: 153
I have a simple jQuery AJAX method that send data to a web method which brings data from da database. When I send number it works properly but I don't know how to send data with parameter.
For example this method works properly:
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");
}
});
}
But this below code does not work and error function raise:
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");
}
});
}
Upvotes: 0
Views: 11490
Reputation: 66389
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");
}
});
Upvotes: 3