URL is the Uniform Resource Locator, which is a type of universal resource identifier URI.
Since a valid URI cannot contain certain characters, such as spaces, etc., if the URI is not encoded using the corresponding encoding function (the browser will process the corresponding URL), then valid resources cannot be accessed. .
There are four URI methods in JavaScript's Global object (javascript's built-in object), namely encodeURI and decodeURI, encodeURIComponent and decodeURIComponent. The browser model (BOM) provides escape and unescape. In practical applications, the URI method is preferable because the URI method encodes all Unicode symbols, while the escape and unescape provided by BOM only encode ASCII symbols. In addition, escape and unescape can be used to encrypt and decrypt data.
Among them, encodeURI and decodeURI are processed in opposite ways, encodeURIComponent and decodeURIComponent are processed in opposite ways, and escape and unescape are processed in opposite ways.
encodeURI handles the complete URI, while encodeURIComponent handles the URI fragment, encodeURI encoding except:! ,#,¥,&,',(,),×, ,,,-,.,/,:,;,=,? , characters other than @, _, ~, 0-9, a-z, A-Z (82 in total), while encodeURIComponent encodes characters other than: !, ', (,), *, -, ., _, ~, 0-9, Characters other than a-z, A-Z (71 in total), escape encodes characters other than: *, , -, ., /, @, _, 0-9, a-z, A-Zs (61 in total).
When requesting a file with a name containing special characters ( ) from the server (the server is a 64-bit operating system), using encodeURI, decodeURIComponent or escape will prompt that the corresponding resource does not exist. Why is this?
js code: