我尝试在 aspx 页面内调用 webmethod,但仅加载页面加载事件。
网络方法:
<WebMethod()> _
Public Shared Function Test() As String
Return "hello"
End Function
ajax 调用:
$.ajax({
type: "POST",
url: "../Custom/Policy.aspx/Test",
dataType: "text",
success: function (data) { alert(data);},
error: function (request, status, error) {
console.log(request.responseText);
}
});
有趣的是,我过去设法让它工作,甚至查看了代码,但我仍然无法让它工作,现在我放弃了......
如有任何帮助,我们将不胜感激。
提前致谢。
最佳答案
问题是我向数据传递了一个 native JSON 对象。一旦我将这个对象作为字符串传递,它就开始工作了!
关于asp.net - 使用 JQuery ajax 调用 webmethod 时调用 page_load,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14548517/