AJAX显示结果只有几秒钟才消失

时间:2016-09-19 17:41:51

标签: javascript ajax



function showUser(str) {
    if (str == "") {
        document.getElementById("res").innerHTML = "";
        return;
    } else { 
        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 (this.readyState == 4 && this.status == 200) {
                document.getElementById("res").innerHTML = this.responseText;
            }
        };
        xmlhttp.open("GET","search.php?q="+str,true);
        xmlhttp.send(null);
		return false;
    }
}

<?php
$q = intval($_GET['q']);

include 'connect.php';
if (!$con) {
    die('Could not connect: ' . mysql_error($con));
}

$rs=mysql_query("select * from webuser where FirstName LIKE '%".$q."%' or MiddleName LIKE '%".$q."%' or LastName LIKE '%".$q."%' or address LIKE '%".$q."%' or contactno LIKE '%".$q."%'
			 or department LIKE '%".$q."%' or position LIKE '%".$q."%' or username LIKE '%".$q."%'",$con);
if(!$rs) { 
    die(mysql_error()); // TODO: better error handling
	echo '<script>alert(mysql_error())</script>';
}
else{
   //code to print here
}
mysql_close($con);
?>
&#13;
&#13;
&#13;

我的代码有问题,ajax会显示结果,但只需一秒或更短时间就会消失。尝试搜索,没有找到。提前致谢。

0 个答案:

没有答案