1

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

data: $('#field1, #field2, #field3').serialize()
santa
  • 123
  • 9
  • These questions may help you [serialize](http://stackoverflow.com/questions/11025594/jquery-serialize-converts-all-spaces-to-plus) and [replaceAll](http://stackoverflow.com/questions/6507056/replace-all-whitespace-characters) – Xeon Feb 13 '14 at 12:23
  • @Xeon: Already read them. – santa Feb 13 '14 at 12:35

1 Answers1

2

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

Arun P Johny
  • 384,651
  • 66
  • 527
  • 531