gpt4 book ai didi

php - jquery ajax 很慢

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:41:43 27 4
gpt4 key购买 nike

我已经建立了一个 ajax 帖子,我正在通过它向另一个 php 文件发送一些数据,最后进行实时搜索......但问题是它有点慢,当我在框中输入内容时,ajax需要 1-2 秒才能触发....我希望搜索像 youtube 的搜索或 facebook 搜索一样,非常快,当我在那里输入内容时它会立即显示建议...有什么想法可以解决这个问题吗?

代码如下:

$("#search").keyup(function(){
var value = $(this).val();
var categ = $("#categ").val();
if (value.length >= 1)
{
$.ajax({
type: "POST",
url: "../core/search.php",
data: { string : value , categ : categ },
success: function(result){
$(".each_movie").hide();
$(".search_movie").remove();
$("#movies").append(result);
}
});
}
else
{
$(".each_movie").show();
$(".search_movie").remove();
}
});

和PHP

$src = $_POST['string'];
$categ = $_POST['categ'];

$sql = mysql_query("SELECT * FROM movies WHERE `$categ` LIKE '%".$src."%' ") or die(mysql_error());
while ($sql_grab = mysql_fetch_assoc($sql))
{
?>
<div class="search_movie">
<p style="margin-bottom:5px;font-family:'Lucida Sans Unicode', 'Lucida Grande', sans-serif;color:rgba(255,255,255,0.3);font-size:12px;">Din: <?php echo $sql_grab['airdate']; ?> in cinematografe.</p>
<table>
<tr>
<td rowspan="2" valign="top"><img class="main_pic" src="<?php echo $sql_grab['mainpic']; ?>" width="180px" /></td>
<td><p class="name"><?php echo $sql_grab['name']; ?></p></td>
</tr>
<tr>
<td><div class="desc_wrapper" id="<?php echo $id; ?>" style="display:inline-block;"><p class="desc"><?php echo mysql_real_escape_string($sql_grab['description']); ?></p></div><p nr="<?php echo $id; ?>" id="more<?php echo $id; ?>" class="more" style="position:absolute;margin:30px 2px;color:rgba(255,255,255,0.2);cursor:pointer;display:inline-block">...citeşte</p></td>
</tr>
</table>
</div><!--each movie end-->
<?php
}

最佳答案

使用 JSON 加速 Ajax 脚本与服务器之间的连接。

关于php - jquery ajax 很慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15921716/

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