search

Home  >  Q&A  >  body text

javascript - URL encoding issues when using native ajax

When I used ajax to send a request to the server and carried parameters written in Chinese (GET and POST), I did not use the encoding and decoding functions related to the URL.
But the parameters were still transmitted to the server normally and were processed by the server. The PHP script is recognized normally.
I would like to ask, is the decoding and encoding operation here done automatically by the browser and server?
If it is done automatically, when do you need to manually call the encoding and decoding function?

怪我咯怪我咯2697 days ago1020

reply all(3)I'll reply

  • 欧阳克

    欧阳克2017-07-05 10:44:31

    Well, the main purpose of using UrlEncode is to prevent parameters from being incorrectly parsed as part of the URL. . .
    This encoding is not the same thing as the string encoding we often say

    reply
    0
  • 学习ing

    学习ing2017-07-05 10:44:31

    Some structures have more than one encoding method, such as arrays: ?a=1&a=2 ?a[]=1&a[]=2, etc. At this time, you may need to manually write it into the one recognized by the server.

    reply
    0
  • typecho

    typecho2017-07-05 10:44:31

    Some browsers will automatically encode and decode, such as chrome, but not all browsers will do this. Therefore, in most cases, please UrlEncode the passed parameters. I am a .NET backend and will decode once by default.

    reply
    0
  • Cancelreply