Click here to Skip to main content
15,867,771 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi!

I have created a web service, I want to send id from ajax post and want to get the
name as response from web service. But I am getting error. when debugg goes on success command
JavaScript
 <script type="text/javascript">
    function callme()
    {
    var postData ={'id':'4'};
    var pdataJSON=JSON.stringify(postData);
          $.ajax({
            type: 'POST',
            contentType: 'application/json',
            url: '/JSON/WebService.asmx/GetName',
            dataType: "json",
            data:pdataJSON,
            success: function(responseText){
                alert(data.responseText);
            },
            error: function(jqXHR, textStatus, errorThrown){
                alert(jqXHR, textStatus, errorThrown);
            }
        });
}
    </script>

Following is a web service

C#
[WebMethod]
   public string GetName(Int32 id)
   {
       var result = from p in obj.tblPersons
                    where p.id == id
                    select p;
       return result.First().name;

   }


please help me
Posted
Updated 2-Nov-12 18:53pm
v2

The webmethod receiving parameter type must be object. because you are sending json object from script not an integer.
C#
[WebMethod]
   public string GetName(Object id)
   {
       var result = from p in obj.tblPersons
                    where p.id == id
                    select p;
       return result.First().name;

   }

please check your code once. it may helps you.
 
Share this answer
 
Comments
ravi sharma11 3-Nov-12 1:30am    
i have done as u said but still same problem. It is going in error
Check this link, it may helps you.

pass JSON object to WCF service[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900