Welcome Guest, Not a member yet? Register   Sign In
Ajax
#1

[eluser]The Casual Bot[/eluser]
Hey this isn’t a CI problem but thought someone could point me in the right direction
I’m make a small demand planning tool first I want to work out my safety stock level’s etc I have a CI page in which I feed in
And numeric length of time i.e. 10
The time span IE. Months
And the product code i.e. abc123

And it comes back with my safety stock level. a lot happens on this page and it takes around 19sec to complete

Currently there’s around 5000 items I have to do this for
So i made a second page which loads a list of stock codes and makes an Ajax request to get the safety stock level

What I’m try to get working is to stop JavaScript from calling all at once I need to have it wait until the Ajax request is complete then move on

im useing jquery .load for the ajax request

Code:
<div id="page">
    <div class="menu clearfix">
     &lt;!-- Page title --&gt;
    <div>Saftey Stock Levels</div>
        <div class="cr_pass"></div>
    </div>

    <div class="clearfix content">
    &lt;?php print_r ($stock); ?&gt;


    

    </div>

[removed]
    $.ajaxSetup ({
        cache: true
    });
        var ajax_load = "<img src='img/load.gif' alt='loading...' />";
      
    

var mycodes = new Array();

&lt;?php
$i = 0;
foreach ($stock2 as $row){
$row['stkcode'] = str_replace('"', "", $row['stkcode']);

          echo 'mycodes['.$i.'] = "'.$row['stkcode'].'";';
          echo "\r";
          $i++;
}
    
?&gt;

for (i=0;i<mycodes.length;i++) {
  var loadUrl = 'safetystock/index/5/weeks/'+mycodes[i];
    var result = mycodes[i];
  
    $('#SYR021H').html(ajax_load).load(loadUrl);
};

[removed]
#2

[eluser]Georgi Budinov[/eluser]
You can use the callback for the load method

http://api.jquery.com/load/

Code:
$("#success").load("/not-here.php", function(response, status, xhr) {
  if (status == "error") {
    var msg = "Sorry but there was an error: ";
    $("#error").html(msg + xhr.status + " " + xhr.statusText);
  }
});

This way you can make a thread of ajax calls using a global js variable for example.




Theme © iAndrew 2016 - Forum software by © MyBB