I am working on something and I have a very weird problem. I submit an AJAX request like following:
x = new XMLHttpRequest();
x.open('POST', url, true);
x.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
x.onload = function(){
console.log(x.responseText);
};
x.send(data);
The problem is, when I submit the request, the PHP doesn't receive the POST
values. The data
variable looks like following:
Object { wordtype: "noun", word: "computer" }
And the PHP like following:
if(!isset($_POST['wordtype']) || !isset($_POST['word'])){
echo "error 1";
exit;
} else {
$wordlist = json_decode(file_get_contents("words.json"), true);
$wordlist[$_POST['word']] = $_POST['wordtype'];
file_put_contents("words.json", json_encode($wordlist));
echo "success";
}
The value of x.responseText
is always error 1
;
Thank You
Jacques Marais