javascript - PHP MySQL jQuery/AJAX issue -


i have problem jquery.

this jquery code:

function updaterecord(id)   {       jquery.ajax({        type: "get",        url: "index.php",        data: 'id='+id,        cache: true,        success: function(data)        {          $('#output').html(data);         }      });  } 

updaterecord(id) data here :

echo"<select>";     foreach($products->fetch_products($id) $product)     {         $price = $product->price;      echo"<option value = $product->id onclick=\"updaterecord($product->id)\">$product->p_name</option>";     }     echo"</select>"; 

this piece of html , php code new result should <div id="output"></div> :

$i = 0;     foreach($products->fetch_products($id) $pricer){     if ($i==1) break;         echo"<td>";     echo"<center>";     echo("<div id=\"output\"><p>$pricer->price</p></div>");     echo"</center>";     echo"</td>";     $i++;     } 

and php function return price :

public function update_price($id){          $stmt = $this->connect()->prepare("select `price` `products` id=?");          $stmt->bindvalue(1,$id);          $stmt->execute();          $row = $stmt->fetchall(pdo::fetch_obj);           //echo json_encode($row);           foreach($row $data){              echo $data->price;           } } 

i tested php function , it's working properly.

the problem when click on dropdwon list , choose product whole table repeating aggain in "price" field :

normal :

http://i44.tinypic.com/34473mp.jpg

problem :

http://i43.tinypic.com/3449xmw.jpg

edit

this table :

<tbody>  <?php     foreach($category->fetch_category() $data){      $id = $data->id;      echo"<tr>";     echo"<td>";     echo"<center>";     echo"<input type=\"hidden\" value=\"$data->id\" />";     echo"<p><strong>".$data->cat_name."</strong></p>";     echo"</center>";     echo"</td>";     echo"<td>";     echo"<center>";      echo"<select>";     foreach($products->fetch_products($id) $product)     {         $price = $product->price;     echo"<option value = $product->id onclick=\"updaterecord($product->id)\">$product->p_name</option>";     }     echo"</select>";      echo"</center>";     echo"</td>";      echo"<td>";     echo"<center>";     echo"<input class=\"input-mini\" type=\"text\" value=\"1\"/>";     echo"</center>";     echo"</td>";     $i = 0;     foreach($products->fetch_products($id) $pricer){     if ($i==1) break;          echo"<td id=\"$pricer->category_id\">";      echo"<center>";     echo("<div id=\"output\"><p>$pricer->price</p></div>");     echo"</center>";     echo"</td>";     $i++;     }     echo"</tr>"; }  ?> <tr> <td></td> <td></td> <td></td> <td>total: </td> </tr>  </tbody> 

thanks in advance ! trying fix whole day...

if sending request same page should check ajax call , work desired part of html got whole html of index.php recommend pass parameter in ajax call , on top of index.php check call

function updaterecord(id)   {       jquery.ajax({        type: "get",        url: "index.php",        data: 'id='+id+'&ajax_call=1',        cache: true,        success: function(data)        {          $('#output').html(data);         }      });  } 

index.php

if($_request['ajax_call']){ $i = 0;     foreach($products->fetch_products($id) $pricer){     if ($i==1) break;         echo"<td>";     echo"<center>";     echo("<div id=\"output\"><p>$pricer->price</p></div>");     echo"</center>";     echo"</td>";     $i++;     } die();  } 

edit

for each category have price div id output therefore id duplicating try

 foreach($products->fetch_products($id) $product)     {         $price = $product->price;     echo"<option value = $product->id onclick=\"updaterecord($product->id,$data->id)\">$product->p_name</option>";     }     echo"</select>";      echo"</center>";     echo"</td>";      echo"<td>";     echo"<center>";     echo"<input class=\"input-mini\" type=\"text\" value=\"1\"/>";     echo"</center>";     echo"</td>";     $i = 0;     foreach($products->fetch_products($id) $pricer){     if ($i==1) break;          echo"<td id=\"$pricer->category_id\">";      echo"<center>";     echo("<div id=\"output-$data->id\"><p>$pricer->price</p></div>");     echo"</center>";     echo"</td>";     $i++;     } 

js

function updaterecord(id,cat_id)   {       jquery.ajax({        type: "get",        url: "index.php",        data: 'id='+id,        cache: true,        success: function(data)        {          $('#output-'+cat_id).html(data);         }      });  } 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -