代碼如下:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="script/jquery-1.3.2.js" type="text/jscript"></script>
<script type="text/jscript">
function show(num) {
var params = '{str:"'+ num+'"}';
$.ajax({
type: "POST",
url: "default.aspx/aa",
data: params,
dataType: "text",
contentType: "application/json; charset=utf-8",
beforeSend: function(XMLHttpRequest) {
$('#show').text("正在查詢");
},
success: function(msg) {
$('#show').text(eval("(" + msg + ")").d);
},
error: function(xhr, msg, e) { alert(msg); }
});
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="click" onclick="show('執行成功');">點擊我! </div>
<div id="show" ></div>
</form>
</body>
</html>
後台方法:
代碼如下:
[System.Web.Services.WebMethod()]
public static string aa(string str)
{
return str;
}