Use the js encodeURIComponent method in asp

Source: Internet
Author: User

As you know, in js, The encodeURIComponent method is a commonly used encoding method. However, due to work needs, this method is required in asp. I have checked a lot of information and there is no good method, finally, the following method is used to solve the problem. Copy codeThe Code is as follows: <%
Function aspEncodeURIComponent (sStr)
AspEncodeURIComponent = myEncodeURIComponent (sStr)
%>
<Script language = "javascript" type = "text/javascript" runat = "server">
Function myEncodeURIComponent (sStr ){
Return encodeURIComponent (sStr );
}
</Script>
<%
End Function
%>

Note:

EncodeURIComponent Method
Encodes a text string into a valid component of a uniform resource identifier (URI.

EncodeURIComponent (encodedURIString)

The required encodedURIString parameter represents an encoded URI component.

Description
The encodeURIComponent method returns an encoded URI. If you pass the encoding result to decodeURIComponent, the initial string is returned. Because the encodeURIComponent method encodes all characters, note that if the string represents a path, for example,/folder1/folder2/default.html, the Slash will also be encoded. In this way, when the encoding result is sent to the web server as a request, it will be invalid. If the string contains more than one URI component, use the encodeURI Method for encoding.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.