Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  7] [ 6]  / answers: 1 / hits: 6990  / 10 Years ago, thu, march 27, 2014, 12:00:00

How can I send a nested object via POST request?



var name = test,
path = ?diffCurr%5B%5D=FALSE&diffProv%5B%5D=FALSE,
data = {
datatype:report,
value:{
name:name,
query:path
}
};

$.ajax({
type:POST,
url: resources/savedata.html,
data: data,
success: function(data){
...
},
complete: function(){
...
}
})


When I check in the chrome, in the network tab under form data, I see this:



datatype:report
value[name]:test
value[query]:?diffCurr%5B%5D=FALSE&diffProv%5B%5D=FALSE


Basically, I was expecting $_POST[value] to contain an object with name and query.


More From » php

 Answers
1

Basically, I was expecting $_POST[value] to contain an object with name and query.




It does.



You are just looking at the raw data which is encoded in application/x-www-form-urlencoded with PHP's square bracket syntax for complex objects.



When PHP deserializes it to populate $_POST, it will do so in the form you expect.


[#46487] Wednesday, March 26, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
shylaelisan

Total Points: 37
Total Questions: 94
Total Answers: 110

Location: Angola
Member since Tue, May 5, 2020
4 Years ago
;