我如何可以加载从其他网站的内容到矿用JavaScript / jQuery的? [英] How can I load content from another site onto mine with JavaScript/jQuery?

查看:99
本文介绍了我如何可以加载从其他网站的内容到矿用JavaScript / jQuery的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让维基百科文章加载到我的网站。我想在这里按照指示: 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文档,你需要传递一个其它附加原产地参数相匹配您的浏览器发送的原产地

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."

这篇关于我如何可以加载从其他网站的内容到矿用JavaScript / jQuery的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆