<!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title> <script src="WebUI/js/clienthint.js"></script>
</head> <body> <form>
First Name:<input type="text" id="txt1" onkeyup="showHint(this.value)" />
</form> <p>Suggestions: <span id="txtHint"></span></p> </body>
</html
var xmlHttp
function showHint(str) {
if (str.length == 0) {
document.getElementById("txtHint").innerHTML = "";
return;
}
xmlHttp =ttpObject()
if (xmlHttp == null) {
alert("您的浏览器不支持ajax");
return;
}
var url = "getint.aspx";
url = url + "?q=" + str;
url += "&sid=" + Math.random();
xmlHttp.onreadystatechange= stateChanged;
xmlHttp.open("GET", url, true);
xmlHttp.send(null); }
function stateChanged() { if (xmlHttp.readyState == 4) {
console.log(xmlHttp.responseText);
document.getElementById("txtHint").innerHTML = xmlHttp.responseText; }
}
function ttpObject() {
var xmlHttp = null;
try{
xmlHttp=new XMLHttpRequest(); }
catch (e) {
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); }
}
return xmlHttp; }
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; namespace DemoItem
{
public partial class getint : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string q = Request.QueryString["q"].ToString();
Response.Write(q);
Response.End();//终止执行代码 }
}
}