Hasta hace poco conocí el JSON.parse. Antes que eso usaba eval para parsear los datos devueltos por AJAX. Para recibir los datos en mis pruebas estoy usando la siguiente función:
Código HTML:
function xAJAX (app,rqs,fnt,isString) { var xh = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP'); xh.open ('POST',app,true); xh.setRequestHeader ('Content-type','application/x-www-form-urlencoded'); xh.onreadystatechange = function () { if(xh.readyState == 4 && xh.status == 200) fnt( JSON.parse(xh.responseText) ); }; xh.send (rqs); };
Código HTML:
Uncaught SyntaxError: Unexpected token ' xh.onreadystatechange