In the use of jquery processing HTML5 application, has been under the Firefox test is normal, users use pad to visit when said there are garbled,
I tried it. Sure enough, after the discovery of chrome and IE kernel is the problem, this problem set the page properties for Utf-8 time, only Firefox is the Charset=utf-8 header file
Chrome and IE are not specified, so there is a garbled problem.
Workaround:
The code is as follows |
Copy Code |
$.ajaxsetup ({ ContentType: "application/x-www-form-urlencoded; Charset=utf-8 " }); $.post ("test.php", {name: "I5a6", Time: "2pm"}, function (data) { Process (data); }, "JSON"); |
or use:
The code is as follows |
Copy Code |
$.ajax ({ Url:url, Type: "POST", Data:data, ContentType: "application/x-www-form-urlencoded; Charset=utf-8 ", DataType: "JSON", Success:function () { ... } }) |
Recommend the use of the first, but also according to their own actual situation to see, some people recommend using encodeURIComponent to do character conversion
Summarize some experience of Ajax submitting data garbled
In order to avoid garbled, you can do the following steps
Solving method
1, maintain the unified coding, including file encoding, database coding, Web Content-type coding
Check the <meta http-equiv= "Content-type" content= text/html; Charset=utf-8″/>
Recommended Chinese are used UTF-8, use gbk/gb2312 may appear garbled
2, use post to send instead of get
The Get method passes the arguments through a link and automatically urlencode (encoding), and the individual browsers may encode differently. Use post to avoid this situation.
3, through the JS front-end escape code and then send, and then the background decoding to obtain data
These can be searched on the internet
4, in the global set ContentType, specify the encoding
Because jquery Ajax is the use of utf-8 to encode the data sent, IE did not add charset=utf-8 when sent, resulting in garbled (ie defaults to use iso-8859-1 code)
code is as follows |
copy code |
$.ajaxsetup ({ contenttype: "application/x-www-form-urlencoded; Charset=utf-8 " }); |