Send JSON object via GET and POST in php without having to wrapping it in another object literal.
Posted
by Kucebe
on Stack Overflow
See other posts from Stack Overflow
or by Kucebe
Published on 2010-04-27T08:30:35Z
Indexed on
2010/04/27
9:13 UTC
Read the original article
Hit count: 187
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?
© Stack Overflow or respective owner