-1
I’m trying to convert an object json
in array
, I have tried several ways using the json_decode()
function Save() {
let post_id = document.getElementById('post_id');
let pergunta = document.getElementById('pergunta');
var dados = {
post_id: post_id.value,
pergunta: pergunta.value
};
var data = JSON.stringify(dados);
console.log(data);
var ajax = new XMLHttpRequest();
ajax.open('POST','index.php?class=PostForm&method=addFormPost', true);
ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
ajax.onreadystatechange = () => {
if (ajax.readyState === 4) {
if (ajax.status === 200) {
console.log(ajax.responseText);
}
}
};
ajax.send(data);
}
my function is executed in the action of click
and I have the following output on file php
array(1) {
["{"post_id":"8","pergunta":"55555"}"]=>
string(0) ""
}
What other way I could use to convert ?
opa beleza ? vc ja olhada na função JSON.parse() ? da uma olhada https://www.w3schools.com/js/js_json_parse.asp
– Jhonatan M Lima