如何使用jquery调用Webmethod? [英] How to call a Webmethod using jquery?

查看:88
本文介绍了如何使用jquery调用Webmethod?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨专家!

我创建了一个web方法: -

Hi Experts!
I have created a webmethod:-

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));
               }

         //  }
       }
   }





当我执行它然后它提供服务方法的链接,即GetDocsCount。使用这个链接。

http:// localhost:52517 / RailMapDoc.asmx

调用方法后我得到我的json数据。

如何使用jquery使用这些数据,下面是我用来使用jquery获取json数据的代码。



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.

var GisMapWithTags = function () {
              $.getJSON("RailMappDoc.asmx/GetDocsCount", function (json) {
                  jsonString = json;
              }).done(function () {
                  ArcGisMap();
              }).fail(function () {
                  alert("Error");
              });
          }





我无法得到da ta,我在做错了请建议我。



谢谢



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

Thanks

推荐答案

.getJSON( RailMappDoc.asmx / GetDocsCount function ( json){
jsonString = json;
})。done( function (){
ArcGisMap();
})。fail( function (){
alert( 错误) ;
});
}
.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


请查看这篇文章并尝试实现与此处相同的代码和规范:



使用jQuery客户端在ASP.NET 2.0中创建JSON WebService [ ^ ]



而不是员工对象上面的演示,你可以回复像



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

return new JavaScriptSerializer().Serialize(docCount);





在你的网络方法中。



inside your webmethod.






我猜这个问题您是否错过了传递参数,在您的web方法中,您传递locAddr作为参数,但在JSON调用中您错过了传递,可能是因为您可能会遇到此类问题。



有关详细信息,请参阅以下链接 http://www.aspsnippets.com/Articles/Send-Pass-multiple-parameters-to-WebMethod-in-jQuery-AJAX-POST-in-ASPNet.aspx [ ^ ]


这篇关于如何使用jquery调用Webmethod?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆