Note that there are some explanatory texts on larger screens.

plurals
  1. POCaching AJAX results with PHP
    text
    copied!<p>I have an AJAX call that retrieves lines from file via JSON. I have 3M rows in my database and I want to show result but I cannot see anything.</p> <p>The results retrieved via JSON I wanted to cache, so that if a data is requested more than once, I will not send request again. What is the best practices for caching in jQuery?</p> <p>I use PHP in my server side. Any suggestions would be appreciated.</p> <p>My JavaScript code:</p> <pre><code>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(); }, }); } </code></pre> <p>And PHP function to get result:</p> <pre><code>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); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload