Search code examples
javascriptencoding

How to prepare encoded POST data on javascript?


I need to send data by POST method.

For example, I have the string "bla&bla&bla". I tried using encodeURI and got "bla&bla&bla" as the result. I need to replace "&" with something correct for this example.

What kind of method should I call to prepare correct POST data?

UPDATED:

I need to convert only charachters which may broke POST request. Only them.


Solution

  • >>> encodeURI("bla&bla&bla")
    
    "bla&bla&bla"
    
    >>> encodeURIComponent("bla&bla&bla")
    
    "bla%26bla%26bla"