I tried to encode all the values, e.g.
encodeURIComponent($("#customer_details").serialize());
and it does not work properly.
Is there a way to get all the elements in a form and use encodeURIComponenteach value to encode?
encodeURIComponent
It should already be encoded using the serialize() [docs] method .
serialize()
From the docs:
The method .serialize()creates a text string in standard encoding with URL encoding.
.serialize()
Example: http://jsfiddle.net/WArUG/
If you want to represent space with %20instead +, you need to do it .replace(/\+/g,'%20').
%20
+
.replace(/\+/g,'%20')