Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save zburgermeiszter/d837e7c62db5e338a596 to your computer and use it in GitHub Desktop.

Select an option

Save zburgermeiszter/d837e7c62db5e338a596 to your computer and use it in GitHub Desktop.
Sending empty arrays with jquery to Symfony
$.ajax({
url:postURL,
type:"POST",
data:JSON.stringify(data),
contentType:"application/json; charset=utf-8",
dataType:"json"
})
public function yourAction()
{
$requestContent = $request->getContent();
if (
0 !== strpos($request->headers->get('Content-Type'), 'application/json') ||
empty($requestContent)
) {
throw new \Exception("Invalid request format.");
}
$config = json_decode($requestContent, true);
$config = is_array($config) ? $config : array();
}
http://silex.sensiolabs.org/doc/cookbook/json_request_body.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment