Hi there,
I m using jquery ajax function to get the data from server and i m getting the data in associative array on success, but now i want to convert that associative array in javascript, how i can convert PHP associative array in javascript array.

Waiting for your quick reply
thanks

the associative array that i get on success is

Array(    
[0] => Array        (            [q_id] => 83            [t_id] => 4            [question] => jjjjs.jfdaskldjf            [option1] => jjjjasdfasdf            [option2] => jjj            [option3] => lll            [option4] => lll            [answer] => lll            [marks] => 22        )   

[1] => Array        (            [q_id] => 84            [t_id] => 4            [question] => This is testing            [option1] => 2            [option2] => 7            [option3] => 8            [option4] => 9            [answer] => 2            [marks] => 2        )    

[2] => Array        (            [q_id] => 85            [t_id] => 4            [question] => hello this is another test            [option1] => a            [option2] => b            [option3] => c            [option4] => d            [answer] => a            [marks] => 2        )    

[3] => Array        (            [q_id] => 86            [t_id] => 4            [question] => another test            [option1] => 8            [option2] => 9            [option3] => 0            [option4] => 1            [answer] => 1            [marks] => 2        )    [4] => Array        (            [q_id] => 87            [t_id] => 4            [question] => last question             [option1] => z            [option2] => x            [option3] => c            [option4] => v            [answer] => c            [marks] => 2        ))1

I also try the json_encode and the data that i m getting on success is

{"o":[{"q_id":"83","t_id":"4","question":"jjjjs.jfdaskldjf","option1":"jjjjasdfasdf","option2":"jjj","option3":"lll","option4":"lll","answer":"lll","marks":"22"},{"q_id":"84","t_id":"4","question":"This is testing","option1":"2","option2":"7","option3":"8","option4":"9","answer":"2","marks":"2"},{"q_id":"85","t_id":"4","question":"hello this is another test","option1":"a","option2":"b","option3":"c","option4":"d","answer":"a","marks":"2"},{"q_id":"86","t_id":"4","question":"another test","option1":"8","option2":"9","option3":"0","option4":"1","answer":"1","marks":"2"},{"q_id":"87","t_id":"4","question":"last question ","option1":"z","option2":"x","option3":"c","option4":"v","answer":"c","marks":"2"}]}

Now how i can get the values against q_id 83

Most likely:

data['o'][0]
//or
data[0]

I also try this but error is Uncaught TypeError: Cannot read property '0' of undefined

now what should i do

Show your AJAX code.

problem solved i only add dataType: 'json' and now its working fine

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.