Saturday, May 11, 2024
 Popular · Latest · Hot · Upcoming
59
rated 0 times [  61] [ 2]  / answers: 1 / hits: 18405  / 12 Years ago, thu, may 31, 2012, 12:00:00

I'm trying to communicate AJAX, JSON to PHP and then PHP returns some data and I'm trying to parse it with Javascrpt.



From the php, server I return,



    echo json_encode($data); 

// it outputs [123,something,and more something]


and then in client-side,



success : function(data){

//I want the data as following

// data[0] = 123
// data[1] = something
// data[3] = and more something
}


But, it gives as;



        data[0] = [ 
data[1] =
data[2] = 1


It is reading each character but I want strings from the array, not individual characters. What is happening here? Thanks in advance, I am new to Javascript and JSON, AJAX.


More From » php

 Answers
112

JSON.parse(data) should do the trick.


[#85244] Wednesday, May 30, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jazminkyrap

Total Points: 631
Total Questions: 89
Total Answers: 109

Location: Finland
Member since Fri, Oct 21, 2022
2 Years ago
;