Trying to send a json data by GET.
Json data:
var data = {
country: {
name: "name",
code: 1
},
department: {},
cars: ["bmw", "ferrari"],
books: []
}
Sending code:
var posting = $.ajax({
url: "/do",
type: "GET",
traditional: true,
data: data,
dataType: "json"
});
posting.done(function (data) {
// handle result
});
If traditional=true the (parsed, decoded) query string is
country[name]:name
country[code]:1
cars[]:bmw
cars[]:ferrari
If traditional=false the (parsed, decoded) query string is
country:[object Object]
department:[object Object]
cars:bmw
cars:ferrari
The desired one should be
country:{"name": "name", "code":1}
cars:bmw
cars:ferrari
or
country:{"name": "name", "code":1}
cars:["bmw", "ferrari"]
In other words, the empty objects and arrays should be omitted. The object should be encoded correctly. Tried with different contentType along with JSON.stringify() without luck. Is there a way to this?