I'm having trouble sending data $_POSTthrough jQuery Ajax. I read everything I can find on this subject, and still I wonβt go anywhere. I even returned to very simple data and still nothing, the JSON data was verified using the JSON validation site. For life, I cannot echo/ print_r/ var_dumpor access any data.
My JavaScript:
$('#updateJSON').click(function(){
var content = [{
"id": 21,
"children": [{
"id": 196
}, {
"id": 195
}, {
"id": 49
}, {
"id": 194
}]
}];
var someText = "someText";
$.ajax({
type: 'POST',
url: 'test.php',
data: {data: content},
cache: false,
success: function(){
alert("success");
console.log(content);
window.location = "test.php";
},
error:function(){
alert('ajax failed');
}
});
});
My PHP:
<?php
if(isset($_POST['data'])) {
$json = stripslashes($_POST['data']);
var_dump(json_decode($json, true));
} else {
echo "No Data";
}
?>
So, I get alert("success"), and then redirected test.php
once when test.phpI get the "No data" echo.
Thank you in advance for your help in resolving this issue.
source
share