带有Ajax的PHP响应速度慢
我正在做一个程序,要求用户基于带有Ajax的PHP响应速度慢,php,mysql,ajax,html-table,response,Php,Mysql,Ajax,Html Table,Response,我正在做一个程序,要求用户基于onKeyup从Mysql表中搜索。但似乎响应时间非常慢,而我没有太多的数据~2873条记录 以下是我的PHP代码: <?php session_start(); if(isset($_SESSION['master'])){ require_once('connect_db.php'); require_once('output_fns.php'); <div id="openModal
onKeyup
从Mysql表中搜索。但似乎响应时间非常慢,而我没有太多的数据~2873条记录
以下是我的PHP代码:
<?php
session_start();
if(isset($_SESSION['master'])){
require_once('connect_db.php');
require_once('output_fns.php');
<div id="openModal6" class="modalDialog6">
<div>
<a href="#close" title="Close" class="close">X</a>
<h2><center>Search Item</center></h2>
<p>
<table>
<tr><td>
<b>Item No. :</b><br />
//User input and onKeyup
<input type="text" value="" id="item_s" autofocus required onKeyUp="related_item(document.getElementById('item_s').value,document.getElementById('store_s').value);">
<td><b>Stor</b><br />
//User select Store by default usually its first store
<select name='store_s' id='store_s'>
<?php
$query = "SELECT * from stores_list";
$result = mysql_query($query);
if(mysql_num_rows($result)>0){
$num = mysql_num_rows($result);
for($i=0;$i<$num;$i++){
$row = mysql_fetch_assoc($result);
echo "<option value='{$row['short']}'>{$row['short']}</option>";
}
echo "</select>";
}
else{
//No Stores Available
echo "No Stores Found !";
}
?>
</td>
</tr>
<tr><td align="center" colspan="3">
//Response Output Here
<div id="txtHint4">Waiting...</div>
</td></tr>
</table>
</p>
</div>
</div>
<?php
}
最后是函数相关的\u项
function related_item(str,str2)
{
if (str=="")
{
document.getElementById("txtHint4").innerHTML="";
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("txtHint4").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","get_item.php?q="+str+"&s="+str2,true);
xmlhttp.send();
}
到目前为止我做错了什么?它应该可以快速从表中获取数据,我不知道大概需要4-5秒的等待时间才能看到数据出现在Response
请注意,项目仅为数字,例如(001200201000)
更新: 我已经检查了chrome开发者工具网络来测试延迟部分,似乎延迟继续
get_item.php
文件这里是结果
Query 0.36
Stalled 0.5
Request Sent 0.14ms
Waiting (TTFB) 77.555ms
Content Download 3.40s
那么这是否意味着我的PHP文件有问题?还有什么其他或更好的方法来增强代码?从表中直接读出。也许我在这里遗漏了一些东西这是因为有人在你的数据库上做了sql注入,现在你有了23609035records@e4c5请你进一步澄清一下,我对这一点还是新手。我们不使用mysql_*函数(当然,除非他们期待sql注入攻击)。至于找出问题所在,查看您的chrome开发者工具网络选项卡,查看最长时间在哪里spent@e4c5好的,我会检查一下,然后再通知你,谢谢。这是因为有人在你的数据库上做了sql注入,现在你有23609035records@e4c5你能再澄清一下吗,我对这一点还不熟悉。一个不使用mysql_*函数(当然,除非他们期待着sql注入攻击)。至于找出问题所在,请查看您的chrome开发者工具网络选项卡,查看最长时间都在哪里spent@e4c5好的,我会查一下,然后再通知你,谢谢。
Query 0.36
Stalled 0.5
Request Sent 0.14ms
Waiting (TTFB) 77.555ms
Content Download 3.40s