I want to POST a data object that contains an array.
I believe the object needs to be serialized before it is posted but I don't know how to do that.
I tried the below but the serialize function I'm using breaks because my object contains an array :
var serialize = function (obj, prefix)
{
var str = [];
for(var p in obj) {
if (obj.hasOwnProperty(p)) {
var k = prefix ? prefix + "[" + p + "]" : p, v = obj[p];
str.push(typeof v == "object" ?
serialize(v, k) :
encodeURIComponent(k) + "=" + encodeURIComponent(v));
}
}
return str.join("&");
};
$.ajax({
type: 'POST',
url: '/xxxx',
data: serialize({
a: 'xxx',
b: 123456,
c: [{d: "xxx", e: "xxx"}, {d: "xxx", e: "xxx"}]
})
});
});