0
ASPX頁面jQuery的AJAX方法不使用的WebMethod
<script>
$(document).ready(function() {
$.ajax({
type: "POST",
url: "WebForm1.aspx/GetData",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
$("#Content").text(response.d);
},
failure: function (response) {
alert(response.d);
}
});
});
</script>
</head>
<body>
<form id="frm" method="post">
<div id="Content">
</div>
</form>
</body>
</html>
代碼背後
public static string GetData()
{
return "This string is from Code behind";
}
我想用ajax這個功能,而無需使用 「WEBMETHOD」。即GetData()
方法,我想在我的.aspx頁面中顯示而不使用Web服務。
你需要WebMethod屬性。 – Zaki