How to prepare encoded POST data on javascript?

前端 未结 5 1116
长发绾君心
长发绾君心 2021-01-04 04:10

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 t

5条回答
  •  一向
    一向 (楼主)
    2021-01-04 04:40

    I want POST the javascript-created hidden form.

    So the question is if encodeURIComponent() should be used on each POST variable.

    I haven't found the answer for Dmitry's (and my) question in this thread. But I have found the answer in this thread.

    In case of form/POST where you have upload field(s) you must use

    , if no upload field is used, you should choose yourself as described here. Submitting the form should do the job completly, so there is no need to use encodeURIComponent() explicitly.

    If you create a Http POST without using a form or without some library which creates a Http POST from your data, then you need choose an enctype= and join data yourselves.

    This will be easy for application/x-www-form-urlencoded, where you will use encodeURIComponent() on each value and join them exactly as for GET request.

    If you decide use multipart/form-data then ....? You should google more how to encode and join them in such case.

提交回复
热议问题