So I have this problem for a while now, and I know there are countless questions on this topic, believe me I tried every solution possible but still does not work.
T
You need to set the data type as json in ajax call.
JQUERY CODE:
$.ajax({
url: "ajax/add-user.php",
type: "POST",
dataType:'json',
data: {name: 'John'},
success: function(data){
console.log(data);
}
});
At the same time verify your backend code(php), whether it can accept json
data ?
If not, configure the header as below:
PHP CODE:
/**
* Send as JSON
*/
header("Content-Type: application/json", true);
Happy Coding :