Jump to content

jquery .load() delays the data load


funbinod
 Share

Recommended Posts

i'm trying to load some divs on some page. but I found that the data load is slow. in stead if I php include that page and echo the var, it echos instantly but if I use jquery load(), it delays it.

 

here is the jquery load() tryout

$(document).ready(function(e) {    $('#cap').load('capquery.php #cap');    $('#curl').load('capquery.php #curl');    $('#ll').load('capquery.php #ll');    $('#pl').load('pl.php #pl');    $('#cura').load('capquery.php #cura');    $('#fa').load('capquery.php #fa');    $('#inv').load('capquery.php #inv');    $('#mea').load('capquery.php #mea');});

why is this?

Link to comment
Share on other sites

i want.

 

I've tried also.

<?phprequire('capquery.php');?><script>$(document).ready(function(e) {	var cap = <?php echo $capstotal; ?>;	var staff = <?php echo $staffstotal; ?>;	var suncr = <?php echo $suncrstotal; ?>;	var pro = <?php echo $prostotal; ?>;	var tax = <?php echo $taxstotal; ?>;	var curl = parseInt(cap) + parseInt(staff) + parseInt(suncr) + parseInt(pro) + parseInt(tax);	var ll = <?php echo $llstotal; ?>;    $('#cap').append(cap);    $('#staff').append(staff);    $('#suncr').append(suncr);    $('#pro').append(pro);    $('#tax').append(tax);    $('#curl').append(curl);    $('#ll').append(ll);});</script>

this work very fine. i just gave a try with .load() and found it to be slow. so i wanted to why this? in the load method, i tried loading specific div, one by one, not everything at once. this why this happens? i just wanted to be clear about this..

Link to comment
Share on other sites

I don't know what's inside capquery.php so I don't fully understand what your code does.

 

The reason it runs faster is because you're not making any extra HTTP requests. jQuery's load() method send an HTTP request, you were calling the load() method eight times.

 

HTTP requests are a slow operation. Each request has to open, send data and close. Most browsers have a limit of two requests to the same domain at the same time, so a new request is not sent until previous ones are finished.

Link to comment
Share on other sites

inside capquery, there is many querys and I've placed the result of the querys inside respective divs and i wish them to use on another pages where they are needed.

 

and yes! i know i can do the same thing with php

Edited by funbinod
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...