更新:
<!DOCTYPE html>
<html>
<head>
<script>
function ajax(user_number) {
var xmlhttp;
// get the ID field for easy access...
var index = document.getElementById("index");
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
// here you get back a response... xmlhttp.responseText
// set the hidden field with new data.
index.value = xmlhttp.responseText;
}
}
// here you make a request to your script to check your database...
xmlhttp.open("GET", "app/search/?number=" + user_number + '&index=' + index.value, true);
xmlhttp.send();
}
function check(user_number) {
// make some validation here...
if (user_number.length > 3) {
ajax(user_number);
} else {
return;
}
}
</script>
</head>
<body>
<p>please enter your secret number</p>
<!-- the hidden field holding the ID -->
<input type="hidden" id="index" name="index" value="334" />
<!-- the search text box where user type his own NUMBER onkeyup it make a request -->
<input type="text" id="user-number" name="user-number" onkeyup="check(this.value);"/>
</body>
</html>