Pass javascript variable to php function using ajax in same file without page refresh
<p>I am using PHP function to display geofences. I want to pass javascript variable to php function in same file without page refresh.</p>

<pre><code>function load(id,type){
if(type===2){
  window.location.href="basic.php?idd=" + id;  // i want to change code here

&lt;?php
   $cir =  get_fence_by_type($_GET['idd']);
   if($cir) {
   foreach($cir as $row){
     $fence_id  = $row['geo_id'];
   }
 }
?&gt;
</code></pre>

<p>PHP function is:</p>

<pre><code>function get_fence_by_type($id){
    $query = "Select * from geofence where geo_id=".$id;
    $result = pg_exec($query);
    $d  = array();
    while($myrow = pg_fetch_assoc($result)) { 
        $d[] = $myrow;
    }   
    return  $d; //returns result in array
}
</code></pre>

<p>javascript <code>window.location.href</code> passes javascript value to php function but it reloads page also.</p>
