繁体   English   中英

如何使用jquery将远程内容加载到对话框中?

[英]How to load a remote content into a dialog box with jquery?

我正在尝试使用jquery加载我的网站的远程内容,但我经常收到错误:

XMLHttpRequest无法加载'anylink_here'Access-Control-Allow-Origin不允许使用Origin 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)执行此操作。

这是不可能的,因为ajax不支持跨域请求,http到https将被视为一个。

您将需要在同一域中使用服务器端代码来为您执行提取。

iframing它怎么样?

<body>
        <p id="open">Click to open</p>
        <div id="dialog" title="window title">
            <p><iframe src="popup.html" ></iframe></p>
        </div>
        <script>

            $('div#dialog').dialog({
                autoOpen : false,
                show : "scale",
                hide : "scale",

            });
            $('#open').click (function (event)
                {
                    if ($("#dialog").dialog("isOpen"));
                    else $("#dialog").dialog("open");
                });

        </script>
    </body>
</html>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM