Document directory
- Syntax
- Return Value
- Description
- Syntax
- Return Value
- Description
When the jquery Ajax post is submitted, the request. querystring obtained in the backend results in hexadecimal garbled characters encoded using escape () to solve this problem.
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> </title>
<SCRIPT src = "jquery/jquery-1.3.1-vsdoc.js" type = "text/JavaScript"> </SCRIPT>
<SCRIPT type = "text/JavaScript">
$ (Document). Ready (function (){
Alert (1)
$ ("# Sub"). Click (function (){
Alert (0 );
VaR filepath = $ ("# typefile"). Val ();
Alert (filepath)
Alert ("escape" + escape (filepath ))
Alert ("Unescape" + Unescape (filepath ))
$. Post ("default. aspx? A = "+ Unescape (filepath) +" & Path = "+ escape (filepath), function (data ){
Alert (data );
}, "Text ");
});
});
</SCRIPT>
</Head>
<Body>
<Input type = "file" name = "typefile" id = "typefile"/>
<Input type = "button" id = "sub" value = "Submit"/>
</Body>
</Html>
Background:
Protected void page_load (Object sender, eventargs E)
{
If (! Ispostback)
{
String Path = request. querystring ["path"];
If (! String. isnullorempty (PATH ))
{
String type = request. querystring ["A"];
Filestream stream = file. openread (PATH );
Byte [] by = new byte [stream. Length];
Stream. Read (by, 0, convert. toint32 (stream. Length ));
String newfilename = datetime. Now. ticks + path. substring (path. lastindexof ('.'));
String savepath = server. mappath ("upfiles //" + newfilename );
File. writeallbytes (savepath, );
Response. Write ("Image Upload successful! ");
Response. End ();
}
}
Note:
Definition and usage
The Unescape () function can decode strings encoded by escape.
Syntax
unescape(string)
Parameters |
Description |
String |
Required. The string to be decoded or reversed. |
Return Value
String is a decoded copy.
Description
This function works like this: Find the character sequence in the form of % XX and % uxxxx (X indicates a hexadecimal number ), decodes character sequences such as Unicode/u00xx and/uxxxx.
Definition and usage
The escape () function can encode a string so that the string can be read on all computers.
Syntax
escape(string)
Parameters |
Description |
String |
Required. The string to be escaped or encoded. |
Return Value
A copy of the encoded string. Some characters are replaced with hexadecimal escape sequences.
Description
This method does not encode ASCII letters and numbers or the following ASCII punctuation marks :-_.! ~ *'(). All other characters are replaced by escape sequences.
Tips and comments
Tip: You can use Unescape () to decode the escape () encoded string.
Note: ecmascript V3 rejects this method. The application uses decodeuri () and decodeuricomponent () to replace it.