Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Experts!
I have created a webmethod:-
C#
public class RailMapDoc : System.Web.Services.WebService
   {

       [WebMethod(EnableSession = true)]
       [ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true)]
       public void GetDocsCount(string locAddr)
       {

          // if (Session["login"] != null)
          // {
               using (Docs2GoEntities db = new Docs2GoEntities())
               {
                   var docCount = db.LocDocMappings.Select(l => new { longitude =       l.tblLocation.longitude, latitude = l.tblLocation.latitude, number_of_documents = db.LocDocMappings.Where(ld => ld.locationId == l.locationId && ld.V01_PR.V01_PG.PRONO == "ABKET").Count() }).Distinct();
                   HttpContext.Current.Response.Write(new JavaScriptSerializer().Serialize(docCount));
               }

         //  }
       }
   }


when I am executing this then it is giving link of service method i.e "GetDocsCount". using this link.
http://localhost:52517/RailMapDoc.asmx"
after invoking the method i am getting my json data.
how to consume this data using jquery, below is the code i am using to get the json data using jquery.
JavaScript
var GisMapWithTags = function () {
              $.getJSON("RailMappDoc.asmx/GetDocsCount", function (json) {
                  jsonString = json;
              }).done(function () {
                  ArcGisMap();
              }).fail(function () {
                  alert("Error");
              });
          }


I am not able to get the data, where i am doing wrong please suggest me.

Thanks
Posted
Comments
Palash Mondal_ 25-Sep-15 7:45am    
Are you getting errors in browser console?
Mukesh Pr@sad 25-Sep-15 7:50am    
no i am not getting any error .
F-ES Sitecore 25-Sep-15 7:46am    
Try changing "jsonString = json;" to "jsonString = json.d;"
Mukesh Pr@sad 25-Sep-15 7:51am    
ok..let me try.
Tell us if you are getting any issues.

Please check this article out and try to implement the code and specifications like its been done here:

Create a JSON WebService in ASP.NET 2.0 with a jQuery Client[^]

Instead of Employee object in the above demo, you can just return like

C#
return new JavaScriptSerializer().Serialize(docCount);


inside your webmethod.
 
Share this answer
 
Hi,

I guess the problem is you missed to pass parameters, In your webmethod you are passing "locAddr" as a parameter but in JSON call you missed to pass that, may be because of that you may face this type of issue.

Refer below link for more information http://www.aspsnippets.com/Articles/Send-Pass-multiple-parameters-to-WebMethod-in-jQuery-AJAX-POST-in-ASPNet.aspx[^]
 
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