3

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

2
  • Use indexes to get array elements response[0].id Commented Dec 19, 2016 at 11:53
  • where is your input box? Commented Dec 19, 2016 at 11:54

1 Answer 1

2

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>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.