title: Load php file with ajax
body: <p>Im using ajax to load the testNew.php file into the Cart.html file. It loads the testNew.php file but when i click on the button add which is in the testNew.php, 0 is being entered in the database and as soon as i click on the add button the page refresh by itself. My problem is that i dont want the page to refresh and want the add button to do the same action as in the testNew.php file(which works correctly).</p>
  
  <pre><code> &lt;script type='text/javascript' src='http://code.jquery.com/jquery-1.6.2.js'&gt;
   &lt;/script&gt;
   &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"&gt;    
      &lt;/script&gt;
   &lt;script&gt;
  
    $(document).ready(function() {
  
     $("#product").click(function() {                
  
    $.ajax({    //create an ajax request to load_page.php
      type: "GET",
      url: "testNew.php",             
      dataType: "html",   //expect html to be returned                
      success: function(response){                    
          $("#responsecontainer").html(response); 
          //alert(response);
      }
  
     });
   });
   });
  
   &lt;/script&gt;
   &lt;/head&gt;
    &lt;body&gt;
  
      &lt;table border="1"&gt;
       &lt;tr&gt;
     &lt;td&gt;
      &lt;input type="button" id="product" name="product"value="View all products"/&gt;
      &lt;/td&gt;   
   &lt;/tr&gt;
  &lt;/table&gt;        
   &lt;div id="responsecontainer"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>Here is the testNew.php which works correctly.</p>
  
  <pre><code>&lt;?php
   include'connect.php';
  
    $image = isset($_REQUEST['image']) ? $_REQUEST['image'] : "";
    $id = isset($_REQUEST['id']) ? $_REQUEST['id'] : "";
    $name = isset($_REQUEST['name']) ? $_REQUEST['name'] : "";
    $price= isset($_REQUEST['price']) ? $_REQUEST['price'] : "";
    $sql="SELECT * FROM product";
     $result = mysql_query($sql);
    if($result&gt;0){
    ?&gt;
    &lt;table border='1'&gt;
  &lt;tr&gt;
   &lt;th&gt;Id&lt;/th&gt;
       &lt;th&gt;Image&lt;/th&gt;
       &lt;th&gt;Name&lt;/th&gt;
       &lt;th&gt;Price MUR&lt;/th&gt;
      &lt;/tr&gt;
       &lt;?php
  
      while ($row = mysql_fetch_array($result)){
  
        ?&gt;                  
  
      &lt;tr&gt;
          &lt;td&gt;&lt;?php echo ($row['id']); ?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;img src=&lt;?php echo $row['image'] ?&gt;  width='120' 
                     height='100'/&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?php echo htmlspecialchars($row['name']); ?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?php echo htmlspecialchars($row['price']); ?&gt;&lt;/td&gt;
             &lt;td&gt;
          &lt;form method="POST" action="" &gt;
              &lt;input type="hidden" name="id" value="&lt;?php echo $row['id']; ?&gt;" /&gt;
              &lt;input type="hidden" name="name" value="&lt;?php echo $row['name']; ?&gt;" /&gt;
              &lt;input type="hidden" name="image" value="&lt;?php echo $row['image']; ?&gt;" /&gt;
              &lt;input type="hidden" name="price" value="&lt;?php echo $row['price']; ?&gt;" /&gt;
              &lt;input id="submit" type="submit" name="submit" value='Add to cart' 
              onclick="add()"/&gt;
          &lt;/form&gt;
           &lt;/td&gt;
         &lt;/tr&gt;
       &lt;?php
        }
      ?&gt;
      &lt;/table&gt;
    &lt;?php
  }
  
  $insert = "INSERT INTO product_add(id, name, price) VALUES ('$id',  '$name','$price')";
    $insertQuery=mysql_query($insert);
  
    ?&gt;
  </code></pre>