This is my code,
function responseLogin(response)
{
var newArray = jQuery.parseJSON(response);
alert(newArray.AccountEmail);
}
This is what is alerted,
{"AccountEmail":["Alphabets and numbers only","Alphabets and numbers only"]}
It has not been converted back to an array and i don’t know why. I get the same result if i just use
alert(newArray);
Thanks
EDIT ___
This is what i get after console.log
AccountEmail
["Alphabets and numbers only", "Alphabets and numbers only"]
0
"Alphabets and numbers only"
1
"Alphabets and numbers only"
EDIT 2 ___
if i use alert on the original response i get
[object Object]
Now i’m no expert at JavaScript but i don’t think that is json.
This was the PHP used to generate it (which i have used before and it has worked)
echo json_encode($this->Account->invalidFields());
Edited to match new question text
If I run this statement in Firebug it works as expected:
What it alerts:
So I’d say there’s something dodgy with your response argument. When you alert the response argument directly it claims to be an Object, but parseJSON requires a well-formed JSON string.
Try grabbing the Firebug FF addon if you don’t have it already. Hit F12 to bring it up, activate the console panel, place a
debugger;statement at the top of your function, and refresh the page. In the Firebug panel right next to the console is a “Watch” you can use to investigate what’s inside theresponsevariable by hovering/clicking on it.Another thing to check: isn’t the PHP script echo-ing anything else before/after the mentioned echo statement?