2

i would like to send a variable on the next page this is what i have at the moment

<? php 
//some code 
$ID = $_GET['ID']; 
echo "<div id='show_here'></div>";

    <script type ="text/javascript">

    $(document).ready(function(){
      setInterval(function(){
          $('#show_here').load('fetch.php') 
      }, 3000);
    });
    </script>

so i would like to send the variable $ID in to the next page i assume it will be something like this .load(fetch.php?=id=$id') but it doesn't work can some one please help me out here i think the first think is to define the variable id in the jQuery part but i do not know how to go about it please help

Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268
james2569
  • 53
  • 4

2 Answers2

2

If I were you, I'd clean that code up properly before anything else.

<? php 
//some code 
$ID = $_GET['ID'];
?>


<div id='show_here'></div>

<script type ="text/javascript">

$(document).ready(function(){
  setInterval(function(){
      $('#show_here').load('fetch.php?id=<?php echo $ID; ?>') // we put the ID here 
  }, 3000);
});
</script>

In your fetch.php file, you'll need to access the $ID via $_GET again.

I'm sticking within the scope of your question here, but something to note is that you best sanitize that information. Especially if you're going to use it in a database query!

Darren
  • 13,050
  • 4
  • 41
  • 79
2

you can use

.load('fetch.php?id=<?php echo $id ?>'); 

or

.load('fetch.php' , {id : '<?php echo $id ?>'}) ;
Mohamed-Yousef
  • 23,946
  • 3
  • 19
  • 28