When you ask me whether they are on the same page, do you mean same file?
Let me clarify on the way my code is organized. Below is the directory structure
ls /var/ww/html
css data exe FirePHPCore-0.3.2 index.html js json php
ls /var/www/html/js
addMac.js
ls /var/www/html/php
addMachine.php
Few lines from index.html (not the entire page).
There is a button on the page too which listens to Click event and calls the JS function.
Code:
</div>
<span id="ipnic0_label">IP Address NIC 0</span>
<input type="text" id="ipnic0_txt" />
</div>
<div>
<span id="owner_label">Owner</span>
<input type="text" id="owner_txt" />
</div>
Few lines from addMac.js (not the entire page)
Code:
var mac_data=new Object();
mac_data.ipaddress_eth0=document.getElementById('ipnic0_txt').value;
mac_data.owner=document.getElementById('owner_txt').value;
var json_data=JSON.stringify(mac_data);
console.log(json_data);
xmlhttp.open("POST","php/addMachine.php",true);
xmlhttp.setRequestHeader('Content-Type', 'application/json')
xmlhttp.send(json_data);
Few lines from addMachine.php (not the entire page)
Code:
var_dump ($_POST);
header("Content-Type: application/json");
I am able to make this work using a "get" request. But the POST is not working for me.