Home >Web Front-end >Front-end Q&A >What to do when jquery reads txt garbled characters

What to do when jquery reads txt garbled characters

藏色散人
藏色散人Original
2021-11-11 09:40:282601browse

The solution to jquery reading garbled txt: 1. Load the page; 2. Execute the code "function (xhr){xhr.overrideMimeType('text/plain; charset=gb2312')..." .

What to do when jquery reads txt garbled characters

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn