Code: Select all
var xhr = new XMLHttpRequest();
xhr.open('POST' , 'updateuserinfo.php');
xhr.setRequestHeader('Content-Type' , 'application/json');
xhr.onload = function() {
if (xhr.status === 200) {
console.log('done !');
}
}
let data = {
name : 'John',
profession : 'Accountent'
}
xhr.send(JSON.stringify(data));
return false;
});
Code: Select all
Notice: Undefined index: data in C:\xampp\htdocs\AjaxUser\updateuserinfo.php on line 3
Code: Select all
<?php
$data = $_POST['data'];
$newUserInfo = json_decode($data, true);
echo $newUserInfo;
?>
Thank you.
Gautam.