• Jquery ajax 访问调用带参数的服务方法!


    页面脚本中的写法:

    $.ajax({
                url: "http://localhost:3510/WebSite/WebService/ExceptionRecoder.asmx/SetExceptionInfo",
                contentType: "application/json; charset=utf-8",                  
                type: "POST",                  
                dataType: "json",                  
                data: "{mStrException:'"+ e +"'}",
                success: function (json) { alert(json.d); }
      });
    

    服务写法: 

    [System.Web.Script.Services.ScriptService]
    public class ExceptionRecoder  : System.Web.Services.WebService 
    {
        /// <summary>
        /// 记录前台传入的信息
        /// </summary>
        /// <param name="ex">异常类内容</param>
        /// <returns></returns>
        [WebMethod(EnableSession = true)]
        public string SetExceptionInfo(string mStrException)
        {
            string errorMethod = null;
            string remark ="";
            LogHelper.Instance().WriteErrorLog(BizLogEnum.SystemError.ToString(), mStrException, mStrException,null, errorMethod, remark);
            return "true";
        }
    }
    

    注意:当前台调用不到带参数的服务时,一般有这两种原因:1可能是因为你前台传参数时候data:拼接参数值不对  2可能是因为服务里面

    “//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。 [System.Web.Script.Services.ScriptService]”这句话可能被注销掉了。

  • 相关阅读:
    青檬音乐台闲时听听电台吧
    [转]What is AOP?
    实现页面元素拖动效果的JS函数
    gorithms.算法概论.习题答案
    Asp.Net读取并显示Excel文件中的内容(OleDb方式)
    收藏的一些小软件
    Master Page Path (MasterPage 相对路径)
    rundll32 netplwiz.dll,UsersRunDll
    关于锁
    我的回帖保存
  • 原文地址:https://www.cnblogs.com/BeyondWJsel/p/2459330.html
Copyright © 2020-2023  润新知