Search code examples
jqueryserializationtabswhitespacestrip

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


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

data: $('#field1, #field2, #field3').serialize()

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