ASP.NET で jQuery を使用して単純な ajax 呼び出しを作成しようとしています。
JavaScript ファイルでの Ajax 呼び出しは次のとおりです。
$.ajax(
{
url: "AjaxCall.aspx/GetSquare",
dataType: "text",
success: function (data) {
alert(data);
},
error: function () { alert("Ajax Error"); }
});
.aspx ファイルの Web メソッドは次のとおりです。
[WebMethod]
public string GetSquare()
{
return "OK";
}
そして、これは私が警戒しているものです:
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
</title></head>
<body>
<form method="post" action="GetSquare" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE2MTY2ODcyMjlkZLfZC2ZpNR/9g+3q7Z3ARCxIRMMXrN2MoePSYHvaiYH3" />
</div>
<div>
</div>
</form>
</body>
</html>
返された値が「OK」ではなく HTML マークアップ全体だったのはなぜですか?