Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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
 <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
 
[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 2-Nov-12 18:52pm
Edited 2-Nov-12 18:53pm
_Amy50.8K
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The webmethod receiving parameter type must be object. because you are sending json object from script not an integer.
[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.
  Permalink  
Comments
ravi sharma11 at 3-Nov-12 1:30am
   
i have done as u said but still same problem. It is going in error
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Check this link, it may helps you.
 
pass JSON object to WCF service[^]
  Permalink  

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



Advertise | Privacy | Mobile
Web03 | 2.8.140926.1 | Last Updated 3 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100