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]”这句话可能被注销掉了。

posted on 2012-04-20 14:55  朝扬  阅读(2818)  评论(0编辑  收藏  举报