-2

我有一个 AJAX 调用,它通过 JSON 从文件中检索行。我的数据库中有 3M 行,我想显示结果,但我什么也看不到。

通过 JSON 检索到的结果我想缓存,这样如果多次请求数据,我就不会再次发送请求。在 jQuery 中缓存的最佳实践是什么?

我在服务器端使用 PHP。任何建议,将不胜感激。

我的 JavaScript 代码:

function GetSearchResult(Char,Company,Category,Country,Page)
{
    $.ajax({
        type: "POST",
        url: "CompanyResult.php",
        data: {
            mySearchChar : Char,
            mySearchCompany : Company,
            mySearchCategory : Category,
            mySearchCountry : Country,
            myPage : Page
              },
        cache: false,
        dataType : "html",
    beforeSend: function(){
        $("#Loading").show(); //show image loading 
        $('html, body').animate({scrollTop:$('#insid_body_web').offset().top}, 'slow');
        $("#ResultCompany1").hide(); 
        $("#ResultCompany2").hide();
        $("#ErrorSearch").hide(); 
    },
    complete: function(){
       $("#Loading").hide(); //hide image loading
       $("#ResultCompany1").show(); 
       $("#ResultCompany2").show();
       $("#ErrorSearch").hide(); 
    },
    success: function(data){
    $(".insid_body_web").html(data);
    $('html, body').animate({scrollTop:$('#insid_body_web').offset().top}, 'slow');
    $("#ResultCompany1").show();
    $("#ResultCompany2").show(); 
    $("#ErrorSearch").hide();
    $(".insid_body_web").css("min-height","1397px");
    },
    error: function() {
    $("#ErrorSearch").show();
    $("#ResultCompany1").hide();
    $("#ResultCompany2").hide(); 
    },
});
}

和 PHP 函数来获得结果:

public function selectallcompanydatabypagingbycat($char,$company,$cat,$country,$from,$records)
{
    $sql ="select company_CompName,company_Phone,company_Site,company_id 
    from company
    where
    company_delete ='0' 
    and company_Request = '0' ";
    if ($cat !=""){ $sql .= " and company_CompCat = '".$cat."' "; }
    if ($company !=""){ $sql .= " and company_CompName = '".$company."' "; }
    if ($country !=""){ $sql .= " and company_country = '".$country."' "; }
    if ($char !=""){ $sql .= " and company_CompName like '".$char."%' "; }
    $sql .= " order by company_id desc limit $from,$records";
    $query = @mysql_query($sql);
    return $query;
    mysql_free_result($query);

}
4

1 回答 1

0

像这样在ajax中更改您的数据

 data: {
            "mySearchChar" : Char,
            "mySearchCompany" : Company,
            "mySearchCategory" : Category,
            "mySearchCountry": Country,
            "myPage" : Page
              },

而在CompanyResult.php

$cat = trim($_POST['mySearchCategory']);
$company = trim($_POST['mySearchCompany']);
$country = trim($_POST['mySearchCountry']);

...... 等等...

于 2013-05-04T09:57:04.853 回答