By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,937 Members | 1,532 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,937 IT Pros & Developers. It's quick & easy.

display json data using AJAX

P: 2

my aim is to display the content of my json data i receive from my php file.

php is sending :


$arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);

echo json_encode($arr);


ajax is receiving "data" and displaying : data = {"a":1,"b":2,"c":3,"d":4,"e":5}

now, how can is display for exemple the item "c" to get "3" something like :

alert(' a = "+..--->what must i put here<-----.);

i tried : date[2], but it is not working ! is says : UNDEFINED

thx for your help

Dec 28 '11 #1
Share this Question
Share on Google+
2 Replies

P: 2


solution :

var obj = jQuery.parseJSON(data);

alert( obj.a);

thx to all for you help !
Dec 28 '11 #2

Expert Mod 5K+
P: 8,639
note: associative arrays in PHP are plain objects in JS (because JS arrays are *always* numerically indexed)
Dec 29 '11 #3

Post your reply

Sign in to post your reply or Sign up for a free account.