ページのコード ビハインド ファイルに 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()も、メソッドは呼び出されません。何か案は?