我在页面的代码隐藏文件中创建了一个 WebMethod,如下所示:
[System.Web.Services.WebMethod()]
public static string Test()
{
return "TEST";
}
我创建了以下 HTML 页面来测试它:
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"/></script>
<script type="text/javascript">
function test() {
$.ajax({
type: "POST",
url: "http://localhost/TestApp/TestPage.aspx/Test",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "text",
success: function(msg) {
alert(msg.d);
}
});
}
</script>
</head>
<body>
<button onclick="test();">Click Me</button>
</body>
</html>
当我单击该按钮时,AJAX 会触发,但没有返回任何内容。当我调试我的代码时,Test()
甚至没有调用该方法。有任何想法吗?