I have the following code
// data is some object
var data = {
getBlocks:{}
};
data['foo'] = 'bar';
jQuery.post(
'http://example.com/foo.php',
data,
function (response) {
....
},
'json'
);
On the server side, the data appears as "[object Object]". In recent PHP versions it is working fine.
Unfortunately upgrading is not an option in the moment due to lots of legacy JQuery code.
How can I fix this?
Use
JSON.stringify()to convert the object to JSON:Depending one the browser you might need to add JSON functions (see json2.js).