jquery读取txt乱码的解决办法:1、加载页面;2、执行代码“function (xhr){xhr.overrideMimeType('text/plain; charset=gb2312')...”即可。

本文操作环境:windows7系统、jquery3.2.1版、DELL G3电脑
jquery读取txt乱码怎么办?
jquery.load读出来的文字乱码
加载txt,中文乱码
jQuery 1.12.4是jQuery 1.x系列的最后一个正式稳定版本,由jQuery团队于2016年发布。该版本主要面向需要兼容旧版浏览器环境的网站和Web应用,尤其适用于仍需支持Internet Explorer 6、Internet Explorer 7、Internet Explorer 8等老旧浏览器的项目。
$("#divattach").load(attachpath, function (data) {
$("#contentID").html(data);
});
在页面加载完成之后,执行这段代码
$(function () {
$.ajaxSetup({
'beforeSend': function (xhr) {
xhr.overrideMimeType('text/plain; charset=gb2312');
}
});
});
推荐学习:《jquery视频教程》










