【发布时间】:2017-06-10 23:59:12
【问题描述】:
JS:
function showComments(couponId) {
var jsontxt = JSON.stringify({ couponId });
$.ajax({
type: "POST",
url: "<% =Page.ResolveUrl("~/Admin/UserCoupons.aspx/GetComments") %>",
data: jsontxt,
contentType: 'application/json; charset=utf-8',
dataType: 'json',
//async:true,
success: function (result) {
alert("We returned: " + result.d);
},
failure: function (response) {
alert(response.d);
}
});
}
C#:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static string GetComments(string couponId)
{
//will return precomipled generated html for display in div
return "Success";
}
C# 代码位于 .cs 文件后面的页面代码中 在使用堆栈溢出之前我已经解决了这一切 感谢这里的专家。 不过这次还有点别的事
我在 page_load 方法中获取调试指针,然后在母版页的页面加载方法中。但调试不进入 GetComments
遇到异常
未知的网络方法 GetComments。 参数名称:方法名
下面是堆栈跟踪
at System.Web.Script.Services.WebServiceData.GetMethodData(String methodName)
at System.Web.Script.Services.RestHandler.CreateHandler(WebServiceData webServiceData, String methodName)
at System.Web.Script.Services.RestHandler.CreateHandler(HttpContext context)
at System.Web.Script.Services.RestHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated)
at System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated)
at System.Web.HttpApplication.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
【问题讨论】:
-
JSON.stringify({ couponId });没有意义.... 你会有{ "foo" } -
@Sadiqabbas Hirani 试试这个 var jsontxt = JSON.stringify({ couponId: val }); //value需要传入val,couponId是参数
标签: javascript c# jquery ajax web-services