I have 2 pages, index.html and dataLoad.php. On page load, dataLoad.php loads all data for the current date and index.html displays this data on a table.
<?php include 'dataLoad.php'; ?>
On button click, a function is called that contains an AJAX that is sent to change the date variable for dataLoad.php so it loads all the data for another day and this information is stored in variables. Now I want to echo the new data values into my html using something like
document.getElementById("hour1").innerHTML = "<?php echo $hour1 ?>";
But even though the page is included, it can not import the new data (it is empty). Is there a a way to import data from the page with the new values?
Thank you for any help!
Use ajax to load your new data (https://api.jquery.com/jquery.post/) like so:
$.post("dataLoad.php", {newId:$yourNewId}, function(data){ $("#hour1").html(data); });
You'll need a function in your php that executes when it gets $_POST['newId']
and have it return only the html you want to place in #hour1
Using a AJAX call to return the data to your current page:
$.ajax({
type: "POST",
url: "dataLoad.php",
data: {data : dataString},
cache: false,
success: function(result) {
var returnedvalue = result;
alert(returnedvalue);
}
});