1

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!

2
  • .load() Load data from the server and place the returned HTML into the matched element. does not send. you might wanna try .post() or .get() Commented Nov 23, 2017 at 13:28
  • @MasivuyeCokile that does not seem to be the problem. .load sends to the server just fine Commented Nov 23, 2017 at 13:36

1 Answer 1

1

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; 
?> 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.