Mam taki skrypt js:
$$('#json_btn').on('click', function () {
var url = "http://localhost/tests/odbierajka_jsonow/index.php";
var data = {
'clients': [
{'id': 123123, 'time': 0},
{'id': 123, 'time': 0},
{'id': 123123, 'time': 0},
{'id': 123, 'time': 0}
],
'instructor_id': 123123};
$.ajax({
dataType: "json",
url: url,
type: "POST",
contentType: 'application/json; charset=utf-8',
// data: JSON.stringify(data),
data: data,
success: function(re){
console.log(re);
},
error: function(er, status){
console.log("error"+JSON.stringify(er)+status);
}
});
});
a php taki
<?php
//header('Access-Control-Allow-Origin: http://localhost:3000' );
header('Access-Control-Allow-Origin: *' );
header('Access-Control-Allow-Headers: content-type' );
header('Content-Type: application/json');
header('Accept: application/json');
$data = $_POST;
//$data = true;
echo json_encode($data);
?>
ale odpowiedź jest taka:
Podejrzewam, że źle wysyłam jsona w post, ale błędu nie wywala, jak usunę kom z $data = true;
to zwraca true