在研究这个问题时,大多数SO问题都是关于将static
方法作为修复方法。
由于它不能与真正的(有点复杂的)WebMethod一起使用,我只是创建了一个简单的WebMethod来检查是否可以访问该方法本身。
[WebMethod]
[ScriptMethod(UseHttpGet = false)]
public static string HelloWorld()
{
return "Hello World!";
}
电话。
<script>
$(document).ready(function () {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "usersWebMethods.aspx/HelloWorld",
dataType: "json",
success: function (data) {
alert(data.d);
}
});
});
</script>
问题总是归结为500(服务器内部错误)
Unknown web method HelloWorld.
Parameter name: methodName
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: Unknown web method HelloWorld.
Parameter name: methodName
为什么会失败?
static
的网络方法不受支持。 - James.html
页面调用方法,但为了测试起见,我只是在.aspx
页面本身中运行JS,我的情况下是usersWebMethods.aspx
。 - Daniel Sh.data
参数了吗?比如data: "{}"
? - James