日期:2014-05-17 浏览次数:20677 次
<?php
/* Created on [2012-5-21] Author[Newton] */
?>
<textarea name="message" rows="10" cols="50" onclick="checkUser()" wrap="off">
Give message please.
</textarea>
<script language="JavaScript" type="text/javascript">
//Ajax
var xmlHttp;
function createXMLHttpRequest() {
if(window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
} else if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
function checkUser(){
createXMLHttpRequest();
url = "action.php?check=ok&ran="+Math.random();
method = "GET";
xmlHttp.open(method,url,true);
xmlHttp.onreadystatechange = show;
xmlHttp.send(null);
}
function show(){
if (xmlHttp.readyState == 4){
if (xmlHttp.status == 200){
var text = xmlHttp.responseText;
alert(text);exit;
//document.getElementById("s2").innerHTML = text; //可将返回信息放入id为s2的div中
}else {
alert("response error code:"+xmlHttp.status);
}
}
}
</script>
#action.php
if(isset($_GET['check'])){
#mysql执行语句,检测用户是否存在
echo "检验中……";
}
------解决方案--------------------