Answer the question
In order to leave comments, you need to log in
Sending boolean values in jQuery.ajax() requests?
$.ajax({<br/>
url : uri,<br/>
type : 'post',<br/>
data : {someBooleanVar1: false, subVar: {someBooleanVar2: true}}<br/>
});
Answer the question
In order to leave comments, you need to log in
I'm sorry, I missed the question about the replacement method. Try like this:
function bools2numbers(arr)
{
for(var i in arr)
{
var o = arr[i];
if(typeof o == 'object')
bools2numbers(arr[i]);
else if(typeof o == 'boolean')
arr[i] = o?1:0;
}
return arr;
}
There is the following option, subject to some obvious limitations (and the presence of jQ 1.4+).
function bool2Int(obj) { $.each(obj, function(i) { if (typeof obj[i] == 'object') { bool2int(this); } else if (typeof obj[i] == 'boolean') { obj[i] = +obj[i]; } }); return obj; } $.ajaxSetup({ processData: false beforeSend: function(xhr, settings) { settings.data = $.param(bool2Int(settings.data)) } });
And why false and true do not roll? What is on the server side? Well, as a last resort, you can probably replace it with regexes, both when sending and when receiving.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question