交叉请求时出错:“Access-Control-Allow-Origin”不允许“Origin”? [英] Error on cross request: "Origin is not allowed by Access-Control-Allow-Origin"?
本文介绍了交叉请求时出错:“Access-Control-Allow-Origin”不允许“Origin”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从另一个网站加载另一个网站中的内容:
I'm trying to load content from one of my sites in another:
<div id='include-from-outside'></div>
<script type='text/javascript'>
$('#include-from-outside').load('http://lujanventas.com/plugins/banner/index.php&callback=?');
</script>
但我收到此错误:
XMLHttpRequest cannot load http://lujanventas.com/plugins/banner/index.php&callback=?. Origin http://lventas.com is not allowed by Access-Control-Allow-Origin.
如何防止它发生?
推荐答案
您使用的网址表明该网站支持JSONP(请参阅 http ://en.wikipedia.org/wiki/JSONP )。如果是这样,你应该能够这样做:
The url you are using suggests the site supports JSONP (see http://en.wikipedia.org/wiki/JSONP). If so, you should be able to do it like this:
<script type="text/javascript">
function handleResponse(json){
var data = JSON.parse(json);
...handle data...
}
</script>
<script src="http://lujanventas.com/plugins/banner/index.php?callback=handleResponse"></script>
这篇关于交叉请求时出错:“Access-Control-Allow-Origin”不允许“Origin”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文