鍍金池/ 問答/網(wǎng)絡(luò)安全  HTML/ 這個亂碼如何解決?

這個亂碼如何解決?

有一種代理的方式來解決跨域的問題,
我要獲得

https://www.cnblogs.com/not-a...

由于跨域不可以直接得到,通過一個專門提供服務(wù)的網(wǎng)站,
http://anyorigin.com/
提供正向代理,讓它獲得數(shù)據(jù)后,轉(zhuǎn)發(fā)給我。

$.getJSON('http://anyorigin.com/go?url=https://www.cnblogs.com/not-alone/articles/8552251.html&callback=?', function(data){
$('#output').html(data.contents);});

 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<p>The content i got with proxy</p>
<p id="output"></p>   

我成功的拿到了數(shù)據(jù),但是全部顯示是亂碼,請問,如何解決?

圖片描述

回答
編輯回答
懶豬

看起來無法解決,因代理網(wǎng)站與原網(wǎng)站用的編碼不一致,代理使用 ISO-8859-1,而原網(wǎng)使用 UTF-8。

2018年6月29日 12:59
編輯回答
心悲涼
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>

<body>
    <p>The content i got with proxy</p>
    <p id="output"></p>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script>
        $.ajax({
            url: 'http://anyorigin.com/go?url=https%3A//www.cnblogs.com/not-alone/articles/8552251.html&callback=?',
            beforeSend: function (jqXHR) {
                jqXHR.overrideMimeType('application/json;charset=utf-8');
            },
            success: function (data) {
                $('#output').html(data.contents);
            },
            error: function (e) {
                var content = e.responseText;
                var data = JSON.parse(content.substr(2, content.length - 3));
                $('#output').html(data.contents);
            }
        })
    </script>
</body>

</html>

clipboard.png

2018年6月13日 07:00