The solution to jquery reading garbled txt: 1. Load the page; 2. Execute the code "function (xhr){xhr.overrideMimeType('text/plain; charset=gb2312')..." .
The operating environment of this article: windows7 system, jquery3.2.1 version, DELL G3 computer
#What should I do if jquery reads txt garbled characters?
The text read out by jquery.load is garbled
Loading txt, Chinese garbled characters
$("#divattach").load(attachpath, function (data) { $("#contentID").html(data); });
Loading on the page After completion, execute this code
$(function () { $.ajaxSetup({ 'beforeSend': function (xhr) { xhr.overrideMimeType('text/plain; charset=gb2312'); } }); });
Recommended learning: "jquery video tutorial"
The above is the detailed content of What to do when jquery reads txt garbled characters. For more information, please follow other related articles on the PHP Chinese website!