的问题:
当触发showCurrentTime()时,永远不会调用WebMethod GetCurrentTime()。
成功功能是触发并显示空警报。
页面上有一个脚本管理器。
嵌入了JQuery。
试过 url:'<%= ResolveUrl(“WebMethodTest2.aspx / GetCurrentTime”)%>'。并得到同样的问题。
尝试启用PageMethods然后按如下方式调用WebMethod并获得相同的问题。
PageMethods.GetCurrentTime(onSuccess, onError);
function onSuccess(resp) { alert(resp.d); }
function onError(resp) { alert(resp.d); }
任何帮助表示赞赏。感谢。
function showCurrentTime() {
$.ajax({
type: "POST",
url: "WebMethodTest2.aspx/GetCurrentTime",
data: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) { alert(response.d); },
failure: function (response) { alert(response.d); }
});
}
[WebMethod]
public static string GetCurrentTime()
{
return DateTime.Now.ToString();
}
答案 0 :(得分:0)
如果其他人遇到这种情况而没有意识到Asp.NET.FriendlyURLs与此问题有关。
在RouteConfig.cs中注释掉
//settings.AutoRedirectMode = RedirectMode.Permanent;