I am going to INSERT an array of objects into mysql via AJAX but on server side json_decode() returns null
How can i solve this?
This is the ajax codes:
let mainObj = [
{ username: 'david', password: 33456, email: '[email protected]' },
{ username: 'rose', password: 3333, email: '[email protected]' },
{ username: 'adam', password: 95112, email: '[email protected]' },
{ username: 'lisa', password: 'sarlak', email: '[email protected]' },
]
let sendMe = JSON.stringify(mainObj);
let xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
document.getElementById('result').innerHTML = xhr.responseText;
}
}
xhr.open("GET", "check.php?x=" + sendMe, true);
xhr.send();
And the php codes (check.php):
$obj= json_decode($_GET['x'], true);
$b= $obj[1]->username;
var_dump($b);
It returns null but i need it returns an array of objects which be usable in database.
print_r($obj)to see what is it.