How to solve the problem of garbled code directly displayed on the page obtained by ajax
This article mainly explains the "ajax access page directly display garbled problem how to solve", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "ajax access page directly display garbled problem how to solve" it!
Solution:
Functiongb2utf8 (data) {varglbEncode= []; gb2utf8_data=data; execScript ("gb2utf8_data=MidB (gb2utf8_data,1)", "VBScript"); vart=escape (gb2utf8_data). Replace (/% ucharg, "). Replace (/ (. {2}) (. {2}) (. {2}) / g,"% $2% pound 1 "). Replace (/% ([Amurz].)% (. {2})% (. {2}) / g," @ $1 $2 "); t=t.split (" @ ") Vari=0,j=t.length,k; while (+ + I k = t [I] .substring (0Power4); if (! glbEncode [k]) {gb2utf8_char=eval ("0x" + k); execScript ("gb2utf8_char=Chr (gb2utf8_char)", "VBScript"); glbEncode [k] = escape (gb2utf8_char) .substring (1d6);} t [I] = glbEncode.substring (4);} gb2utf8_data=gb2utf8_char=null
With this code, you can directly encode the content of the returned web page:
Varresponse=gb2utf8 (response.responseBody)
Of course, if the server-side page is encoded in utf-8, there is no need for coding at all.
Thank you for your reading, the above is the "ajax access page directly display garbled problem how to solve" the content, after the study of this article, I believe that everyone on the ajax access page directly display garbled problem how to solve this problem has a deeper understanding, the specific use of the need for everyone to practice and verify. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!