james2569 james2569 - 6 months ago 12
Javascript Question

send a varible through load functon

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

Answer

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!

Comments