Using the MVC model I am currently trying to send data to my controller using the object XMLHttpRequest. I would like to use the POST method. When I send the data I can only get the GET variables.
object_profile.prototype.addSkill = function(skill){
if(typeof skill == "string"){
console.log(skill)
let xhr = new XMLHttpRequest()
const URL = this.url_topepite+"profile/jsAddSkill"
console.log(URL)
xhr.open("POST", URL)
xhr.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
let dataToSend = JSON.stringify({
skill: skill
})
xhr.onreadystatechange = function(){
if(xhr.readyState == 4 || xhr.status == 200){
console.log(xhr.responseText)
}
}
xhr.send(JSON.stringify({ email: "hello@user.com", response: { name: "Tester" } }));
}
}
<pre class='xdebug-var-dump' dir='ltr'>
<small>C:\wamp64\www\olad2\app\controllers\Profile.php:131:</small>
<b>array</b> <i>(size=0)</i>
<i><font color='#888a85'>empty</font></i>
</pre><pre class='xdebug-var-dump' dir='ltr'>
<small>C:\wamp64\www\olad2\app\controllers\Profile.php:132:</small>
<b>array</b> <i>(size=1)</i>
'url' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'profile/jsAddSkill'</font> <i>(length=18)</i>
</pre>
Is it a problem of JSON or due to the setRequestHeader ?
Thanks !