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