[英]Webservice method not found by JQuery Ajax-Request error 500
JS: 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#: C#:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static string GetComments(string couponId)
{
//will return precomipled generated html for display in div
return "Success";
}
The C# code is in page's code behind .cs file i have solved this all before using stack over flow thanks to experts here. C#代码在.cs文件后面的页面代码中,在这里,我已经解决了所有这些问题,这要归功于这里的专家。 but this time there is some thing else
但是这次还有别的东西
i am getting my debug pointer in page_load method then in master page's page load method. 我在page_load方法中获取调试指针,然后在母版页的页面加载方法中获取调试指针。 but debug doesn't enters to the GetComments
但是调试不会进入GetComments
and getting exception 并获得例外
Unknown web method GetComments.
未知的Web方法GetComments。 Parameter name: methodName
参数名称:methodName
Below is the stackTrace 下面是stackTrace
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)
Your data in ajax should be JSON.stringify({ couponId:'123' }) //parameter name & value. 您在ajax中的数据应为JSON.stringify({couponId:'123'}) //参数名称和值。
function showComments(couponId) {
var jsontxt = JSON.stringify({ couponId:'123' });
$.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);
}
});
}
after a long google and all others and applying every possible solutions. 经过漫长的谷歌和所有其他人,并应用所有可能的解决方案。 finally, i found a solution.
终于,我找到了解决方案。 and that's edit the file at ~/App_start/RouteConfig.cs
然后在〜/ App_start / RouteConfig.cs中编辑文件
replace 更换
settings.AutoRedirectMode = RedirectMode.Permanent;
with 同
settings.AutoRedirectMode = RedirectMode.Off;
this solved my problem. 这解决了我的问题。 any ways thanks to all who took interest and showed their generosity.
无论如何,都要感谢所有感兴趣并表现出慷慨的人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.