您的位置:首页 > Web前端 > JQuery

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

2012-04-20 14:55 579 查看
页面脚本中的写法:

$.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]”这句话可能被注销掉了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐