如何使用jquery将远程内容加载到对话框中?
我正在尝试使用 jquery 加载站点的远程内容,但我不断收到错误:
XMLHttpRequest 无法加载 '此处任意链接' 不允许原点为 null 访问控制允许来源。
这是我的代码:
jQuery(function(){
$('#checkout').submit(function(e){
//prevent default behavior and hide possibly existing pop-up
e.preventDefault();
//process request
var form = this;
var url = form.action;
var dialog = $('<div id="lightbox_dialog"></div>').appendTo('body');
// load remote content
dialog.load(
url,
function (response, status, xhr){
dialog.html(response);
});
dialog.dialog();
//prevent the browser to follow the link
return false;
});
});
和表单代码:
<form id="checkout" action='http://me.me/' method='get'>
<input type="image" class="class1" onclick="this.form.action='http://en.wikipedia.org/wiki/Sample'" title="Title" value="" src="http://4cornersautoloan.com/images/SmallButton.gif">
</form>
我还需要为同一域执行此操作,但从 http 到 https。
I'm trying to load a remote content of my site with jquery, but I constantly get an error:
XMLHttpRequest cannot load
'anylink_here'
Origin null is not allowed by
Access-Control-Allow-Origin.
Here is my code:
jQuery(function(){
$('#checkout').submit(function(e){
//prevent default behavior and hide possibly existing pop-up
e.preventDefault();
//process request
var form = this;
var url = form.action;
var dialog = $('<div id="lightbox_dialog"></div>').appendTo('body');
// load remote content
dialog.load(
url,
function (response, status, xhr){
dialog.html(response);
});
dialog.dialog();
//prevent the browser to follow the link
return false;
});
});
And a form code:
<form id="checkout" action='http://me.me/' method='get'>
<input type="image" class="class1" onclick="this.form.action='http://en.wikipedia.org/wiki/Sample'" title="Title" value="" src="http://4cornersautoloan.com/images/SmallButton.gif">
</form>
I also need to do it for the same domain but from http to https.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这基本上是不可能的,因为ajax不支持跨域请求,http到https将被视为跨域请求。
This is not possible basically because ajax doesn't support cross-domain request and http to https will be regarded as one.
您将需要同一域上的服务器端代码来为您执行提取。
You will need server-side code on your same domain to perform the fetching for you.
把它嵌入到 iframe 中怎么样?
How about iframing it in?