我用一些方法为搜索数据库创建了一个PHP类。即 LIKE
、FULL TEXT
和 ...
我确实在一个巨大的数据库上测试了它。搜索速度非常快,所以我开始在我的页面中使用这个脚本。
我决定使用 AJAX 来加快速度...
这是我的 ajax 代码:
$.ajax({
type: "POST",
data: publisher + '&blur=true',
url:"server/advance2.php",
ifModified: true, /* tested with and without this */
cache: true, /* tested with and without this */
statusCode: { 404: function() {
$('#target').html('<h4 class="col-md-offset-4 col-md-3 textRed textCenter farsi">Error...</h4>');
}//404
},//statusCode
beforeSend: function() {
$('#target').html('<img src="e995a9c2864f.gif" class="col-md-offset-4 col-md-3" alt="We are searching, please wait"/>');
},
success: function(result) {
$('#target').html(result)
}
});//Ajax Request After Blur
但搜索速度明显下降。
您能告诉我为什么会发生这种情况以及如何解决它吗?
最佳答案
一些快速调试的想法:
1) 打开浏览器调试器,通常以 F12 启动,确保响应的大部分时间都在等待 Web 服务器(与渲染等)。
2)在服务器端,找到数据库查询日志并查看查询本身实际花费了多长时间。正如其他答案中所指出的,这里有许多移动部件。您只需要一步步找到比预期花费时间更长的那个即可。
关于php - 为什么使用ajax查询速度很慢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29860517/