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.