I got this code in game.php to refresh .refre, but I always get "parsererror". jsonString is from jsonString= JSON.stringify(object);
<div class="refre"></div>..
<script>...
jsonString ={"right":0,"arrayQ":[{"0":"10","idQ":"19"},
{"0":"34","idQ":"20"},{"0":"89","idQ":"14"}],"lives":40};
$.ajax({
type: 'POST',
data: jsonString,
dataType: 'json',
url: 'Q.php',
contentType : 'application/json; charset=utf-8'
}).done( function (data, status) {
$('.refre').load('Q.php');
alert('Right');
})
.fail( function (data, status) {
alert("Wrong: "+status);
});
...</script>
The other file is Q.php, this read the POST and send some HTML, Now It is just for check the information of the POST.
<?php
$value = json_decode($_POST);
$categories = json_decode(file_get_contents('php://input'));
print_r($value);
print_r($categories);
?>
What's wrong with the ajax?? how I get the POST in Q.php? how can I get 'lives' from the JSON in Q.php?
Try this,
<div class="refre"></div>..
<script>...
jsonString =[{"right":0,"arrayQ":[{"0":"10","idQ":"19"},
{"0":"34","idQ":"20"},{"0":"89","idQ":"14"}],"lives":40}];
$.ajax({
type: 'POST',
data: jsonString,
dataType: 'html',
url: 'Q.php',
contentType : 'application/json; charset=utf-8'
}).done( function (data, status) {
$('.refre').html(data);
alert('Right');
})
.fail( function (data, status) {
alert("Wrong: "+status);
});
...</script>
<?php
$value = json_decode($_POST);
$categories = json_decode(file_get_contents('php://input'));
print_r($value);
print_r($categories);
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With