我面臨以下問題:每當我點擊button
時,alert
顯示undefined
。Ajax與asp.net aspx返回未定義
Web方法:
[WebMethod]
public static string getTest()
{
return "testing success";
}
阿賈克斯腳本
<script type="text/javascript">
function getTest() {
$.ajax({
type: "POST",
url: "main.aspx/getTest",
data: "{}",
datatype: "json",
contenttype: "/application/json; charset=utf-8",
success: function (msg) {
alert(msg.d);
},
error: function (data) {
}
});
}
</script>
contenttype:「/ application/json; charset = utf-8」從應用程序的開始處刪除/ – Mairaj