Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get value of json array

I have this jquery function that call a php function and return an array

$.ajax({
    url: 'json/orders.php',
    type: 'post',
    data: { "value" : value },
    success: function(response) {

      ... how? ...

    }
});

This is the array :

[{"id":"560","price":"13.93","id_tax_rules_group":"1","reference":"CR332"}]

The array is always of 1 row... How to get value that I use to update input value?

Thanks

like image 637
FireFoxII Avatar asked Aug 13 '26 14:08

FireFoxII


1 Answers

From your url json/orders.php I assume that your php page return a json object in the response so you could use jsonParse() or $.parseJSON() to parse it like :

response = $.parseJSON(response);

The get the attribute you want like :

response.id
response.price
response.reference

Hope this helps.

var response = $.parseJSON('{"id":"560","price":"13.93","id_tax_rules_group":"1","reference":"CR332"}');

console.log(response.id, response.price, response.id_tax_rules_group);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
like image 162
Zakaria Acharki Avatar answered Aug 15 '26 05:08

Zakaria Acharki