lilgezuz Posted September 1, 2013 Share Posted September 1, 2013 I'm using the following script to load information into a div. It works fine expect I want to make it do more and can't figure it out. <script> function loadingAjax(div_id) { var divIdHtml = $("#"+div_id).html(); $.ajax({ type: "POST", url: "testmash.php?tag=<? echo $ptag; ?>", data: "tag=John&id=28", beforeSend: function() { $("#loading-image").show(); $('#message').html("Importing Profile Information"); }, success: function(msg) { $("#"+div_id).html(divIdHtml + msg); $("#loading-image").hide(); $('#message').html("Successfly Imported Information"); } }); } </script> So I got 3 or 4 php pages that access a api. I want each page to process then return the message into my div. So I could either combine all my php pages into one page and have the message get returned depending on what function the php is running or load them one by one. I'm not sure how to do that. When page one is loading I want it to say something like Importing Page 1 details when it gets done I want it to say successfully imported page 1 details then below that says importing page 2 details, so by the time the fourth page is getting processed it will say Successfully Imported Page 1 Successfully Imported Page 2 Successfully Imported Page 3 Importing Page 4 Sorry this is hard for me to explain I hope someone can help. Thanks ahead of time Quote Link to comment https://forums.phpfreaks.com/topic/281765-loading-php-pages-in-order-through-ajax/ Share on other sites More sharing options...
Irate Posted September 1, 2013 Share Posted September 1, 2013 You can use a for-loop for this. Possibly also dynamically compute the amount of pages you want to load before you use a hard-coded constant. Quote Link to comment https://forums.phpfreaks.com/topic/281765-loading-php-pages-in-order-through-ajax/#findComment-1447725 Share on other sites More sharing options...
lilgezuz Posted September 1, 2013 Author Share Posted September 1, 2013 You can use a for-loop for this. Possibly also dynamically compute the amount of pages you want to load before you use a hard-coded constant. I'm new to using ajax, jquery, and java so I'm not 100% sure how to do a for loop in this case Quote Link to comment https://forums.phpfreaks.com/topic/281765-loading-php-pages-in-order-through-ajax/#findComment-1447730 Share on other sites More sharing options...
Irate Posted September 1, 2013 Share Posted September 1, 2013 Hm, okay, assuming you have your PHP code adjusted a bit already by adding an additional GET parameter (let's call it "p", for page). for(var i = 1; i <= 4; i++) { $.ajax({ url: "testmash.php?tag=<?php echo $ptag; ?>", data: "tag=<?php echo $ptag; ?>&id=<?php echo $id; ?>&p="+i // carry on with the rest... I'll get to explaining the PHP parts }); }So far the JavaScript (with a little support from PHP), for the PHP side, you need to check the directory of the file by doing something like readdir($dir), then do what you are trying to implement with your PHP right now (I cannot elaborate on what to do right now because you never actually posted your testmash.php, but that's okay - just look up the file functions PHP offers you). Quote Link to comment https://forums.phpfreaks.com/topic/281765-loading-php-pages-in-order-through-ajax/#findComment-1447735 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.