Question

How to strip all whitespaces (like spaces, tabs, newlines) from jQuery Ajax Data?

data: $('#field1, #field2, #field3').serialize()
Was it helpful?

Solution

Try something like

var array = $('#field1, #field2, #field3').serializeArray();
$.each(array, function(i,o){
    o.value = o.value.replace(/\s/g, '');
})
....
data: array

Demo: Fiddle

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top