I am trying to consume a JSON string built with the JS function JSON.stringify(objects)
. On my working local version, it is working, but on the server it raises the following error:
invalid argument supplied for foreach
After some investigations, the $POST table is empty. But in the browser console, the data is sent with the query.
Here is the content of the request:
rencontres:[{"id":"1","m":"","f":"0-2","e":"","p":"","status":"3","st":false,"si":false,"se":false,"sp":false,"ss":false}]
Here is the JSON string contained in $GET['rencontres']
(accessed by $request->get("rencontres")
):
[{"id":"1","m":"","f":"0-2","e":"","p":"","status":"3","st":false,"si":false,"se":false,"sp":false,"ss":false}]
which seems correct.
Here some var_dump results: var_dump($renontres) gives [][]
var_dump($request->get("rencontres") gives also [][]
here is the method itself:
public function postSaveRencontre(Request $request){
$em = $this->getDoctrine()->getManager();
$rencontres = json_decode($request->get("rencontres"), true);
//log struff
foreach ($rencontres as $key => $r) {
//blablabla
}
//return statement
}
and here the AJAX statement (url is correct):
$.ajax({
type: "POST",
url:"url",
data: {rencontres:JSON.stringify(rencontres)},
success:function(data){
console.log("save performed");
}
});