Yrtymd
Yrtymd

Reputation: 433

jQuery .load() with get parameters

Need to send AJAX data with get parameters from php variable

<?php
  $startdate="2017-11-23 14:32:00";
?>

<script>  
  setInterval(function() {
    $("#load").load("loader.php", {startdate:<?php echo $startdate;?>});
  }, 10000); 
</script>  

loader.php

<?php
  $startdate=$_POST['startdate'];
?>
<script>
  $("#load").empty();   
  $("#load").html('<?php echo $startdate;?>');  
</script>  

But nothing returns to block "load". Where is my fault? Thanks!

Upvotes: 1

Views: 372

Answers (1)

mplungjan
mplungjan

Reputation: 177940

You likely want something like this.

Note the quotes in the JSON string and also look in the console (F12) I added jQuery too. You need to load that to run the script you have

index.php

<?php
$startdate="2017-11-23 14:32:00";
?>
<div id="load"></div>
<script src="jquery.js"></script>
<script>  
setInterval(function() {
  $("#load").load("loader.php", {"startdate":"<?php echo $startdate;?>"});
}, 10000); 
</script>  

loader.php - html is an example

<?PHP 
  $startdate=$_POST['startdate']; 
  // do something with it
  echo "I <b>received</b> and <i>processed</i> ".$startdate; 
?> 

Upvotes: 1

Related Questions