Passing JSON data from JavaScript using Ajax to PHP

BulletxxProof89

New Member
I have the following JS:\[code\]window.onload = function() {'use strict';var ajax = getXMLHttpRequestObject();ajax.onreadystatechange = function() { if ( ajax.readyState == 4 ) { if ( (ajax.status >= 200 && ajax.status < 300) || (ajax.status == 304) ) { var data = http://stackoverflow.com/questions/15840522/JSON.parse(ajax.responseText); var file =''; file += 'Original: ' + data['org'].file + '<br>'; file += 'Processed: ' + data['pre'].file + '<br>'; document.getElementById('output').innerHTML = file; } else { document.getElementById('output').innerHTML = 'Error: ' + ajax.statusText; } }};document.getElementById('btn').onclick = function() { ajax.open('POST', 'resources/test.json', true); ajax.setRequestHeader('Content-Type', 'application/json'); ajax.send(null);};};\[/code\]I would like to pass the data from \[quote\] data['org'].file\[/quote\]and \[quote\] data['pre'].file\[/quote\]to PHP and have it echo out the value using the POST method. Please no jQuery solutions this needs to be strictly JavaScript.Something like this:\[code\]<?php $data = http://stackoverflow.com/questions/15840522/$_POST['the_data']; echo $data; ?>\[/code\]Here is the JSON from test.json:\[code\]{"org": { "file": "css/original.css"},"pre": { "file": "css/preprocessed.css"}}\[/code\]
 
Back
Top