设为首页 加入收藏

TOP

Jquery ajax调用webservice总结(一)
2017-10-10 12:31:22 】 浏览:8836
Tags:Jquery ajax 调用 webservice 总结

jquery ajax调用webservice(C#)要注意的几个事项:

1、web.config里需要配置2个地方

<httpHandlers>
      <remove verb="*" path="*.asmx"/>
      <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    </httpHandlers>
在<system.web></system.web>之间加入
<webServices>
      <protocols>
        <add name="HttpPost" />
        <add name="HttpGet" />
      </protocols>
    </webServices>

2.正确地编写webserivce的代码

  1 /// <summary>
  2     /// UserValidate 的摘要说明
  3     /// </summary>
  4     [WebService(Namespace = "http://tempuri.org/")]
  5     [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  6     [System.ComponentModel.ToolboxItem(false)]
  7     // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
  8      [System.Web.Script.Services.ScriptService]
  9     public class UserValidate : System.Web.Services.WebService
 10     {
 11         DFHon.Content.Common.rootPublic rp = new DFHon.Content.Common.rootPublic();
 12         [WebMethod]
 13         [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
 14         public string ValidateUserLogState()
 15         {
 16             string result = "";
 17             HttpCookie cookie = HttpContext.Current.Request.Cookies["DHFonMenberInfo"];
 18             if (cookie != null)
 19             {
 20                 string username = System.Web.HttpUtility.UrlDecode(cookie["MenberName"]);
 21                 int ipoint = 0;
 22                 int gpoint = 0;
 23                 try
 24                 {
 25                     DataTable dt = UserBll.ExecuteUserAllInfo(username);
 26 
 27                     if (dt.Rows.Count > 0)
 28                     {
 29                         ipoint = int.Parse(dt.Rows[0]["iPoint"].ToString());
 30                         gpoint = int.Parse(dt.Rows[0]["gPoint"].ToString());
 31                     }
 32                 }
 33                 catch
 34                 { }
 35                 result = "{'user':{'id':'" + cookie["UserId"] + "','name':'" + username + "','message':'" + rp.getUserMsg(DFHon.Global.CurrentCookie.UserName) + "','ipoint':'" + ipoint.ToString() + "','gpoint':'" + gpoint.ToString() + "'}}";
 36             }
 37             else
 38             {
 39                 result = "{'user':{'id':'0','name':'','message':'0','ipoint':'0','gpoint':'0'}}";
 40             }
 41             return result;
 42         }
 43 
 44         [WebMethod]
 45         [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
 46         public string UserLogin(string userName, string userPwd)
 47         {
 48             string returnVal = "";
 49             try
 50             {
 51                 GlobalUserInfo info;
 52                 DFHon.Content.UserLogin _UserLogin = new DFHon.Content.UserLogin();
 53                 EnumLoginState state = _UserLogin.PersonLogin(HttpUtility.UrlDecode(userName), userPwd, out info);
 54                 if (state == EnumLoginState.Succeed)
 55                 {
 56                     DFHon.Global.CurrentCookie.Set(info);
 57                     DFHon.API.PDO.DiscuzNT.PassportLogin.UserLogin(Server.UrlDecode(userName), userPwd, -1);
 58                     int ipoint = 0;
 59                     int gpoint = 0;
 60                     DataTable dt = UserBll.ExecuteUserAllInfo(userName);
 61 
 62                     if (dt.Rows.Count > 0)
 63                     {
 64                         ipoint = int.Parse(dt.Rows[0]["iPoint"].ToString());
 65                         gp
首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇[js高手之路] html5 canvas教程 -.. 下一篇脚本加载优化方法

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目