【发布时间】:2020-08-05 05:52:37
【问题描述】:
我有一个网站,我需要从我的浏览器发送一个 GET 请求并取回 HTML 数据。但是该网站有一个“X-Frame-Option: DENY”,由于 CORS 政策,我无法发出 Ajax 请求。所以我用 JSONP 进行了尝试,但它没有返回任何数据。它确实说 200 OK 连接。我使用的是最新版本的 Chrome。
// Not returning HTML back
$.getJSON("https://www.google.com/?callback=?", function(result) {
console.log(result)
})
// I tried this but also didn't work
$.ajax({
url: 'https://www.google.com',
dataType: 'jsonp',
success: function(result) {
console.log(result)
}
})
我不确定这里发生了什么..
【问题讨论】:
-
X-Frame-Option不是 CORS 标头,它只是防止页面显示在 (i) 框架中。你想达到什么目的?强制谷歌在 iframe 中显示? -
我想向该站点发出 GET 请求并返回 HTML
-
在自己的服务器上读取文件,或者使用代理服务器。
标签: javascript ajax jsonp same-origin-policy