$.ajax({
url : uri,
type : 'post',
data : {someBooleanVar1: false, subVar: {someBooleanVar2: true}}
});
The problem is that on server someBooleanVar1 and someBooleanVar2 will be received as strings "false" and "true", but not as "0" and "1". Is there any way to automatically convert boolean arguments to "1" and "0"?
jQuery provides several methods for AJAX functionality. With the jQuery AJAX methods, you can request text, HTML, XML, or JSON from a remote server using both HTTP Get and HTTP Post - And you can load the external data directly into the selected HTML elements of your web page!
ajax returns immediately and the next statement, return result; , is executed before the function you passed as success callback was even called.
There is a fixed version of @jcubic Answer:
function convertBoolToNum(obj) {
$.each(obj, function(i) {
if (typeof obj[i] == 'object') {
convertBoolToNum(this);
}
else if (typeof obj[i] == 'boolean') {
obj[i] = Number(obj[i]);
}
});
}
$.ajax = (function($ajax) {
return function(options) {
convertBoolToNum(options.data);
return $ajax(options);
};
})($.ajax);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With