RNK
RNK

Reputation: 5792

extract json array in jquery php

I have an array like this:

[{"City":"TORONTO ","FSA":"M5T","Province":"ON\r"}]

I am getting this data from,

echo json_encode($data);

I want to put city and province in text field through ajax jquery success.

I tried this in jquery success:

data = JQuery.parseJSON(data);
$('txtCity').val(data.City);

But, I am not getting actual data.

Upvotes: 1

Views: 135

Answers (1)

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

Reputation: 67217

You have an array.

Try this,

data = JQuery.parseJSON(data);
$('txtCity').val(data[0].City);

Upvotes: 2

Related Questions