php - 为什么使用ajax查询速度很慢?

标签 php jquery mysql ajax

我用一些方法为搜索数据库创建了一个PHP类。即 LIKEFULL 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/

相关文章:

php - 我被困在 mysql 中的一个查询上

php - 查询字符串的 htaccess 问题

javascript - 获取点击事件上的插入符位置

mysql - 讲师有2个教学科目

mysql - 缺少数据库

php - jquery datatables mysql php DataTables警告(表ID ='displayData'): DataTables warning: JSON data from could not be parsed

php - Laravel Scheduler 以 root 用户身份创建缓存文件

jquery - nextSelector 在无限滚动中不更新

javascript - 使用 "rel"属性定位 AJAX 结果在正确的 DIV 中

php - 客房和可用日期 PHP/MySQL