FireFoxII
FireFoxII

Reputation: 828

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

Upvotes: 3

Views: 103

Answers (1)

Zakaria Acharki
Zakaria Acharki

Reputation: 67505

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>

Upvotes: 2

Related Questions