16

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?

2
  • We need to see the ASP code that parses the JSON object POST parameter. Commented Feb 2, 2009 at 15:53
  • 1
    modify ur URL url=url+'?param1='+value1+'&&param2='+value2; this might serve u Commented Oct 18, 2012 at 14:22

4 Answers 4

35

Found the solution:

It should be:

"{'Id1':'2','Id2':'2'}"

and not

"{'Id1':'2'},{'Id2':'2'}"
Sign up to request clarification or add additional context in comments.

Comments

5

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?

Comments

4

i have same issue and resolved by

 data: "Id1=" + id1 + "&Id2=" + id2

Comments

2

I think the best way is:

data: "{'Ids':['2','2']}"

To read this values Ids[0], Ids[1].

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.