Convert PHP query to AJAX Query and Update views with ajax -
i have following script trying convert ajax:
html:
<form action="php/additem.php" method="post" class="form-inline pull-right"> <h4>'.$row['itemname'].'</h4><input id="itemname" type="hidden" name="itemname" value="'.$row['itemname'].'"> <h3>$'.$price.'</h3><input id="price" type="hidden" name="pricetotal" value="'.$price.'"> <img src="../wholesale/img/sourdough.jpg" class="img-reponsive"> <p>'.$row['description'].'</p><input id="description" type="hidden" name="description" value="'.$row['description'].'"> <div class="form-group"> <label class="sr-only" for="exampleinputamount">qty</label> <div class="input-group"> <input id="qty" type="number" name="qty" class="form-control" id="exampleinputamount" placeholder="how many?"> </div> </div> <button type="submit" id="additem" class="btn btn-primary">add</button> </form>
php:
session_start(); include('db_config.php'); $date = date("y-m-d"); $itemname = $_post['itemname']; $description = $_post['description']; $qty = $_post['qty']; $price = $_post['pricetotal'] * $qty; $id = $_session['customer_id']; $sql = "insert orders (deliverydate, customerid, itemname, qty, price) values (?, ?, ?, ?, ?)"; $stmt = $conn->prepare($sql); $stmt->execute(array($date, $id, $itemname, $qty, $price));
now script adding item table orders table. in actual page displays data have 2 sections , ajax query retrieves data both tables.
the ajax retrieves , displays data both tables: not additem ajax:
$(document).ready(function(){ $('.date-picker').change(function(){ $.ajax({ type: 'post', url: 'php/getproduct.php', data: {dateorderpicker: $('.date-picker').val()}, datatype: 'json', success: function(data) { $("#cartrow").html(data.result_1); $("#otheritems").html(data.result_2); } }); }); });
my question need re-retrieve , display these 2 tables again using additem script? result will, item move dynamically orders section?
i hope makes sense. thank guys
php function () { $var = $_post['fieldname']; //enter insert code here..... if($query == success) { return "success"; } }
on ajax call
php function
or
the .php file have mentioned php function insert data.
finally display response on ajax
thats it.
Comments
Post a Comment