<!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 runat="server">
<title>Ajax</title>
<script type="text/javascript">
var xmlhttp;
function createXMLHttpRequest() {
if (window.ActiveXObject) {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
}
}
function startRequest() {
createXMLHttpRequest();
var inputText = document.getElementById("txtId");
xmlhttp.onreadystatechange = handleStateChange;
xmlhttp.open("GET", "Default2.aspx?yourparm=" + inputText.value, true);
xmlhttp.send(null);
}
function handleStateChange() {
if (xmlhttp.readyState==4) {
if (xmlhttp.status == 200 || xmlhttp.status == 0) {
alert(xmlhttp.responseText);
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="text" id="txtId" value="11" onblur="startRequest();" />
</div>
</form>
</body>
</html>
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default2 : System.Web.UI.Page
{
void Page_Load() void Page_Load(object sender, EventArgs e)
{
string request = Request.QueryString["yourparm"].ToString();
Response.Write("你輸入的東西是" + request + "經過ajax調用的");
}
}