Home >Web Front-end >JS Tutorial >Introduction to the use of special symbols in URL_javascript skills

Introduction to the use of special symbols in URL_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:59:501083browse

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:

Copy code The code is as follows:

url =" http://192.168.6.135/nas135/MyDocument/1 2.txt"
window.open(EncodeURI(url),"","","");

via debug I saw
EncodeURI(url)="http://192.168.6.135/nas135/MyDocument/1+2.txt", but I can’t open the file 1 2.txt on the server side. I don’t know if it’s because of 64 The reason for the machine? Could you guys please help explain?
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn