Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
142
rated 0 times [  145] [ 3]  / answers: 1 / hits: 20781  / 11 Years ago, thu, december 26, 2013, 12:00:00

First I want admit that I have no knowledge in ajax. I'm building a small application, where I have a load.php file and within it, I have echoed 3 variables, i.e $loadout[0]; $loadout[1]; $loadout[2];
The PHP file is working fine and showing up the values.
Now I have another html page index.html which will actually users see. In this html file have 3 divs on the body



<div id=out1></div>
<div id=out2></div>
<div id=out3></div>


Now I want you people to help me with the ajax code, which will keep reloading the load.php file of mine and keep updating the output values on the respective div. But index.html page will not reload. load.php will reload inside hiddenly in every 1 sec.



Please help. What will be the ajax code?


More From » php

 Answers
24

In your load.php at the end:



echo json_encode($loadout);


In index.html



<script type=text/javascript src=https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js></script>

<script type=text/javascript>

//Calling function
repeatAjax();


function repeatAjax(){
jQuery.ajax({
type: POST,
url: 'load.php',
dataType: 'json',
success: function(resp) {
jQuery('#out1').html(resp[0]);
jQuery('#out2').html(resp[1]);
jQuery('#out3').html(resp[2]);

},
complete: function() {
setTimeout(repeatAjax,1000); //After completion of request, time to redo it after a second
}
});
}
</script>

[#73536] Tuesday, December 24, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
amari

Total Points: 736
Total Questions: 111
Total Answers: 90

Location: Saint Pierre and Miquelon
Member since Fri, Jan 28, 2022
2 Years ago
;