Send JSON object via GET and POST without having to wrapping it in another object literal, and manag
- by Kucebe
My site does some short ajax call in JSON format, using jQuery.
At client-side i'd like to send object just passing it in ajax function, without being forced to wrap it in an object literal like this: {'person' : person}.
For the same reasons, at server-side i'd like to manage objects without the binding of $_GET['person'] or $_POST['person'].
For example:
var person = {
'name' : 'John',
'lastName' : 'Doe',
'age' : 32,
'married' : true
}
sendAjaxRequest(person);
in php, using:
$person = json_decode(file_get_contents("php://input"));
i can get easily the object, but only with POST format, not in GET.
Any suggestions?