I tried to encode all values like
encodeURIComponent($("#customer_details").serialize());
and that doesn't work as expected.
Is there way to get all elements on form and use encodeURIComponent
to encode each value?
The serialize() method creates a URL encoded text string by serializing form values. You can select one or more form elements (like input and/or text area), or the form element itself. The serialized values can be used in the URL query string when making an AJAX request.
To serialize a FormData object into a query string, pass it into the new URLSearchParams() constructor. This will create a URLSearchParams object of encoded query string values. Then, call the URLSearchParams. toString() method on it to convert it into a query string.
In JavaScript, for example, you can serialize an object to a JSON string by calling the function JSON. stringify() . CSS values are serialized by calling the function CSSStyleDeclaration. getPropertyValue() .
It should already be encoded when using the serialize()
[docs] method.
From the docs:
The
.serialize()
method creates a text string in standard URL-encoded notation.
Example: http://jsfiddle.net/WArUG/
If you want to represent a space with a %20
instead of a +
, you'll need to do a .replace(/\+/g,'%20')
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With