Ajax Post method in jquery submits data

Source: Internet
Author: User
Tags character set json

Example

<! DOCTYPE html>
<Html>
<Head>
<Script src = "js/jquery. min. js">
</Script>
<Script>
$ (Document). ready (function (){
$ ("Button"). click (function (){
$. Post ("demo_test_post.asp ",
  {
Name: "Donald Duck ",
City: "Duckburg"
},
Function (data, status ){
Alert ("Data:" + data + "\ nStatus:" + status );
});
});
});
</Script>
</Head>
<Body>
<Button> send POST data and obtain returned results </button>
</Body>
</Html>

Garbled data submitted by ajax post

The tests in firefox are normal, and both chrome and ie kernel have this problem,

When the page attribute is set to UTF-8, only firefox is the character set = UTF-8 header file.
Chrome and ie are not specified, so garbled characters occur.

Solution:


$. AjaxSetup ({
ContentType: "application/x-www-form-urlencoded; charset = utf-8"
});
$. Post ("test. php", {name: "i5a6", time: "2 "},
Function (data ){
Process (data );
}, "Json ");
 
Or use:


$. Ajax ({
Url: url,
Type: "POST ",
Data: data,
ContentType: "application/x-www-form-urlencoded; charset = utf-8 ",
DataType: "json ",
Success: function (){
...
  }
})
 
To sum up, ajax garbled text is a Chinese problem. You only need to edit the page to uft8. You can usually use contentType: to define the type, of course, you can also use the conversion function to operate upon acceptance.

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.