【发布时间】:2016-04-11 02:39:11
【问题描述】:
我有两个页面,一个在另一个页面的 iframe 中运行:test.php 在 check.php 中运行。 Test.php 的作用是作为一个代理来规避跨域。 iframe 工作并提供正确的值。但是当我尝试从父页面中的 div id 中获取一个值时,我得到了这个响应: 未捕获的安全错误:阻止了来源为“http://localhost”的框架访问来源为“http://www.allow-any-origin.appspot.com”的框架。协议、域和端口必须匹配。
这是我的代码:
检查.php
<iframe id="vd" src="http://localhost/vd/test.php/test.php" width="720"
height="300" frameborder="0" scrolling="no" allowtransparency="true">
</iframe>
<form>
<input id="test" type="button" value="Submit">
</form>
<script type="text/javascript">
jQuery('#test').click(function() {
var mb =
document.getElementById('vd').contentWindow.document.getElementById
('#saldo_result');
});
</script>
test.php
<form action="http://www.allow-any-
origin.appspot.com/http://vend.giftcardservices.nl/saldo/check?
show_form=0&card_id=3005&card_id=&ajax=1" method="GET">
<input type="text" name="card_id" value="3005">
<input type="text" name="card_id" value="">
<br>
<input type="submit" value="Submit">
我认为这条路径是让浏览器接受这种方式。有人能看出我哪里出错了吗?
【问题讨论】:
-
如果该站点正在设置 CORS,请使用 Ajax。如果不在您的域上创建一个代理来获取它。
-
我想我就是这样做的。
标签: javascript jquery iframe cross-domain reverse-proxy