javascript - Encode - Decode Json issue -
i try connect chrome extension php file xmlhttprequest.
work fine, can use json.parse decode json.
js file:
var client = new xmlhttprequest(); client.onreadystatechange = function() { if (client.readystate == xmlhttprequest.done) { var j = client.responsetext; console.log(j); } } client.open("get", "http://localhost/extencio/index.php?"+o, true); client.send();
in php file return object with:
echo json_encode($ofinal);
the result of console.log(j); is:
{"textodonde":"nombre","value":"gettext","donde":"name"}{"textodonde":"apellido","value":"gettext","donde":"name"}{"textodonde":"sexo","value":"type no detectoado","donde":"name"} {"textodonde":"sexo","value":"type no detectoado","donde":"name"}
i change line in js file decode:
var j = json.parse(client.responsetext);
but have other error:
uncaught syntaxerror: unexpected token {client.onreadystatechange @ popup.js:66 vm71:1 uncaught syntaxerror: unexpected token {client.onreadystatechange @ popup.js:66
66 "var j" line.
console.log
outputting multiple json objects?!echo json_encode
ing in loop? you're not sending valid json! send[]
array if want send multiple values. – deceze♦ jan 27 '16 @ 15:45