gpt4 book ai didi

javascript - 当我按空格键时,它会转储完整数据库

转载 作者:行者123 更新时间:2023-12-02 16:37:37 26 4
gpt4 key购买 nike

我有这个代码:

$q = mysql_real_escape_string($_GET["q"]);
$result = mysql_query("SELECT * FROM articles WHERE news_title LIKE '%{$q}%'") or die(mysql_error());
$tablecount = 0;

if(mysql_num_rows($result) != 0){
while($staff = mysql_fetch_array($result)){
echo("

{$staff['news_month']}
{$staff['news_day']}
{$staff['news_year']}
&raquo <a href=\"entry/{$staff['id']}\">{$staff['news_title']}</a><br />

");
}
} else {
echo("Error");
}

因此,当我按下“空格键”时,它会转储数据库中的所有内容。我被困在如何不允许按下空格键清空数据,但我又被困住了!

这是我的 JavaScript:

    function showResult(str){
if (str.length==0){
document.getElementById("livesearch").innerHTML="";
document.getElementById("livesearch").style.border="0px";
return;
}

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){
document.getElementById("livesearch").innerHTML=xmlhttp.responseText;
document.getElementById("livesearch").style.border="0px solid #A5ACB2";
}
}
xmlhttp.open("GET","_lib/_php/livesearch.php?q="+str,true);
xmlhttp.send();
}

最佳答案

trim 字符串以删除周围的空格。

function showResult(str) {
str = str.trim();
...
}

关于javascript - 当我按空格键时,它会转储完整数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27790820/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com