javascript - How to append json array to value attribute -
there search box in view.
when search product on here retrieve(single) product using ajax
my ajax code is
<script> $(function() { $("#update_prod").click(function(event) { event.preventdefault(); var head = $("#update_product").val(); $.ajax({ datatype: 'json', type: "post", url: "<?php echo base_url(); ?>index.php/admin/update_product", data: { product: head }, success: function(data) { } }); }); }); </script>
so in controller
public function update_product() { $product = $_post['product']; $query = $this - > db - > query("select * product title '%$product%' , online=1"); $result = $query - > result_array(); echo json_encode($result); }
and im reviving data in console
[{ "id": "99", "brand_id": "8", "category_id": "1", "mark": "0", "title": "corsair memory - 1gb 533mhz ddr2 desktop memory(vs1gb533d2 ", " model ": " corsair memory - 1 gb ", " sub ": " corsair memory - 1 gb ddr2 desktop memory ", "price": "3250", "price_update": "1", "description": "", "overview": "1", "offer": "0", "stock": "0", "online": "1", "other": "0", "video": "0", "valid": "price valid 2 weeks only" }]
my question is how retrieve data , append value of below input tags
<input type="text" class="form-control" name="new_title" value="">//title should come here <input type="number" class="form-control" name="new_price" value="">//price should come here <select class="form-control" name="new_price_update">//if price_update==1 yes should select, else no select <option value="1">yes</option> <option value="0">no</option> </select>
note : check stack question unable find better solution this
try this,
success: function(data) { var obj = $.parsejson(data); console.log(obj[0]['title']); console.log(obj[0]['price']); //etc.. }
i hope work..
Comments
Post a Comment