Jquery Ajax post submit garbled Solution

Source: Internet
Author: User
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.

 

Related Article

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.