'How to pass multiple parameters in json format to a web service using jquery?
I'm trying to execute a asp.net webservice using jquery. When I pass only one input parameter it works fine:
$.ajax({
type: "POST",
url: url,
data: "{'Id1':'2'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: callback
});
but if I try to pass multiple parameters it fails
$.ajax({
type: "POST",
url: url,
data: "{'Id1':'2'},{'Id2':'2'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: callback
});
Of course, when I try to pass 2 input parameters, I modify the web method so that it takes 2 input parameters.
Any ideas?
Solution 1:[1]
This is a stab in the dark, but maybe do you need to wrap your JSON arguments; like say something like this:
data: "{'Ids':[{'Id1':'2'},{'Id2':'2'}]}"
Make sure your JSON is properly formed?
Solution 2:[2]
i have same issue and resolved by
data: "Id1=" + id1 + "&Id2=" + id2
Solution 3:[3]
I think the best way is:
data: "{'Ids':['2','2']}"
To read this values Ids[0], Ids[1].
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mark W |
| Solution 2 | Sufiyan Ghori |
| Solution 3 | TonBR |
