I am using AJAX for the first time and try to send data to my PHP controller with an XMLHttpRequest. Unfortunately, the data arrives empty there.
request.onload = () => {
let responseObject = null;
try {
responseObject = JSON.parse(request.responseText);
} catch (e) {
console.error('Could not parse JSON!');
}
if (responseObject) {
handleResponse(responseObject);
}
};
const requestData = `title=${this._title.value}&reference=${this._reference.value}&area=${this._area.value}`;
request.open('post', 'checknews');
request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
request.send(requestData);
Whats wrong ?