<?php echo '{"one":"one_text","two":"two_text"}'; ?>
function makeRequest() { httpRequest = new XMLHttpRequest(); httpRequest.onreadystatechange = function () { getProduct(httpRequest); }; url = 'test.php'; httpRequest.open('POST', url, true); httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); httpRequest.send(null); } function getProduct(httpRequest) { var jsonText = httpRequest.responseText; jsonText = jsonText.json; document.write(jsonText.one); }
var jsonText = JSON.parse( httpRequest.responseText );
httpRequest.onreadystatechange = function() { if (httpRequest.readyState === 4 && httpRequest.status === 200) getProduct(httpRequest.responseText); };