I'm trying to swap out jQuery.ajax for mootools.Request. And for some reason the server doesn't receive the same data. This is somewhat troubling because don't want to have to do any extra server-side work.
ajax_request = function(method, url, data, cb) {
// MOOTOOLS *does not work in some cases*
new Request({
method: method,
url: url,
data: data,
headers: {
'Content-type': 'application/json'
},
encoding: 'utf-8',
onSuccess: function(res) {
return cb(JSON.decode(res));
},
}).send();
/* OLD JQUERY REQUEST
$.ajax({
url: url,
type: method,
data: JSON.encode(data),
dataType: 'json',
contentType: 'application/json; charset=utf-8',
success: function(res) {
return cb(res);
}
});
*/
}The server logs the following:
jQuery:
{ pos: 1,
current_num: 1,
filter: { on: '', key: '' },
num_records: 25,
emptyObject: {},
id: 419 }MooTools:
{ pos: '1',
current_num: '1',
filter: { on: '', key: '' },
num_records: '25',
'': '',
id: 419 }Mootoos with encoded data:
In order to preserver the emptyObject I JSON.endode(args) but I just get's encoded twice since Request aleady encodes it.
{ '{"pos":1,"current_num":1,"filter":{"by":"","value":""},"emptyObject":{}}': '', id: 419 }My problem is basically that empty objects are replaced with empty quotes. Any idea why this could be happening and how to fix it?
Thanks