我如何可以加载从其他网站的内容到矿用JavaScript / jQuery的?加载、内容、网站、jQuery

由网友(梦想的初衷)分享简介:我试图让维基百科文章加载到我的网站。我想在这里按照指示: http://en.wikipedia.org/wiki/Wikipedia :WikiProject_Transwiki 但我无所适从。 我已经试过:VAR XYZ = document.getElementById(url("http://en.wikipe...

我试图让维基百科文章加载到我的网站。我想在这里按照指示: http://en.wikipedia.org/wiki/Wikipedia :WikiProject_Transwiki 但我无所适从。

我已经试过:

  VAR XYZ = document.getElementById(url("http://en.wikipedia.org/w/index.php?title=Special:Export&history=1&action=submit&pages=Albert_einstein")

VAR XYZ = $('#xyz').load('http://en.wikipedia.org/w/index.php?title=Special:Export&history=1&action=submit&pages=Albert_einstein');

文件撰写(XY​​Z);
 

解决方案

如果您使用的是最新的浏览器,你应该能够使用CORS。根据维基百科的API文档,你需要传递一个其它附加原产地参数相匹配您的浏览器发送的原产地

3种状态 5种模式,从UX角度分析加载设计

http://en.wikipedia.org/w/api.php

  

的起源 - 当使用跨域访问API   AJAX请求(CORS),将其设置为原始域。                           这必须匹配起源发祥地之一:头完全,所以它被设置成类似    http://en.wikipedia.org 或的 https://meta.wikimedia.org 。                           如果该参数不探源不匹配:头,403响应将被退回。                           如果该参数相匹配的起源:头和原点白名单中,访问控制 - 允许 - 产地标头   将被设置。

I'm trying to get a wikipedia article to load onto my site. I'm trying to follow the instructions here: http://en.wikipedia.org/wiki/Wikipedia:WikiProject_Transwiki but I'm at a loss.

I've tried:

var xyz = document.getElementById(url("http://en.wikipedia.org/w/index.php?title=Special:Export&history=1&action=submit&pages=Albert_einstein")

var xyz = $('#xyz').load('http://en.wikipedia.org/w/index.php?title=Special:Export&history=1&action=submit&pages=Albert_einstein');

document.write(xyz);

解决方案

If you are using a modern browser, you should be able to use CORS. According to the Wikipedia API docs, you need to pass an additionnal origin parameter that matches the Origin header sent by your browser.

http://en.wikipedia.org/w/api.php

"origin - When accessing the API using a cross-domain AJAX request (CORS), set this to the originating domain. This must match one of the origins in the Origin: header exactly, so it has to be set to something like http://en.wikipedia.org or https://meta.wikimedia.org . If this parameter does not match the Origin: header, a 403 response will be returned. If this parameter matches the Origin: header and the origin is whitelisted, an Access-Control-Allow-Origin header will be set."

阅读全文

相关推荐

最新文章