Garbled error in the gbk file of the JS request Server

Source: Internet
Author: User

Garbled error in the gbk file of the JS request Server

When JS obtains a file whose server encoding format is gb2312, the content is garbled. The ajax network request uses XMLHttpRequest internally. Therefore, you need to set the encoding format before the request, but set xhr. setRequestHeader (accept, text/csv; charset = gb2312, */*); no effect. Only xhr is set. overrideMimeType (text/csv; charset = gb2312); is correct, the Code is as follows:

 

$. Ajax ({type: get, url: http://7xnhdv.com1.z0.glb.clouddn.com/test1.csv, beforeSend: function (xhr) {// beforeSend defines the global variable // xhr. setRequestHeader (accept, text/csv; charset = gb2312, */*); xhr. overrideMimeType (text/csv; charset = gb2312) ;}, success: function (xmlDoc, textStatus, xhr) {if (xhr. status = 200) {$ ('# view0 '). text (xmlDoc );}}});
OverrideMimeType overwrites the header sent to the server and forces text/csv; charset = gb2312 as the mime-type.

 

XMLHttpRequest instructions


 

 

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.