Note that there are some explanatory texts on larger screens.

plurals
  1. POVariable speed of response with jQuery Ajax requests
    primarykey
    data
    text
    <p>When I perform an asynchronous request with jQuery Ajax, sometimes the response is returned quickly in 800 ms, somtimes it's slow and the response is returned in 2.50s (avg), and sometimes it hangs, and just shows the loading images. I'm not sure if it's because of my PHP code or jQuery Ajax code. I send some values using jQuery Ajax: </p> <pre><code>function get_detail_product(obj) { var id = obj.id ; var $this = jQuery('#'+id); var Thumb = jQuery('#Scroller div.Container') ; jQuery.each(Thumb , function(){ jQuery(this).css('border' , '#ccc 2px solid'); }); $this.parent().css('border' , '#ff8500 2px solid') ; var load_area = jQuery('.detail') ; //ajax request load_area.html(""); load_area.html('&lt;div id="loading" style="margin-top:60px;margin-left:350px;"&gt;&lt;img src="../images/loading.gif"&gt;&lt;br&gt;Loding ... &lt;/div&gt;'); jQuery.ajax({ url: 'index.php?module=product&amp;popup=on ', type: 'POST', data: 'pid=' + id , success: function(result) { jQuery('#response').remove(); load_area.html(result); jQuery('#loading').fadeOut(500, function() { jQuery(this).remove(); }); } }); } </code></pre> <p>and in the PHP file I have the following code to retrieve the requested data: </p> <pre><code>//ajax requests if(isset($_POST['subcatid']) &amp;&amp; is_numeric($_POST['subcatid'])) { $subcatid = $_POST['subcatid'] ; $products = $dbc-&gt;getAll("select * from xxproduct where xsubcatid='$subcatid'") ; //send result echo '&lt;table cellpadding="0" cellspacing="0" border="0" id="ScrollerTable"&gt;&lt;tr&gt;'; foreach ($products as $p) : echo '&lt;td&gt;&lt;div style="border:#ccc 2px solid ; padding:0px;margin-top:20px ; margin-bottom:20px ; margin-left:8px ; margin-right:8px;" class="Container"&gt;&lt;a href="javascript:void(0)" id="'.$p['xproductid'].'" onclick="get_detail_product(this)" &gt;&lt;img src="imgsize.phpw=100&amp;h=100&amp;img=../uploads/product/'.$p['xproductid'].'/'.$p['xproductid'].'__1.jpg" border="0"/&gt;&lt;/a&gt;&lt;div style="background-color:#ccc ;text-align:center ; padding:5px; "&gt;'.$p['xproductname'].'&lt;/div&gt;&lt;/div&gt;&lt;/td&gt;'; endforeach ; echo ' &lt;/tr&gt;&lt;/table&gt;'; } </code></pre> <p>I wonder if you can find any mistakes in my code that cause the delay; additionally I'm using a PEAR DB object to interact with the database. </p> <p>When i type the title of my question in this page, suggestions are returned in about 500 ms. Why is this ajax interaction so fast but mine is not?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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