2010-11-18 48 views
0

我试图加载我的网站使用jQuery的远程内容,但我不断地得到一个错误:如何使用jquery将远程内容加载到对话框中?

XMLHttpRequest cannot load 'anylink_here' Origin null is not allowed by Access-Control-Allow-Origin.

这里是我的代码:

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。

+2

看到这个主题,我相信:http://stackoverflow.com/questions/4106993/ajax-cross-sub-domain-requests – 2010-11-18 16:27:15

+0

这里:http://stackoverflow.com/questions/4142779/ help-getting-getting-json-format-data-from-external-website/4142817#4142817 – 2010-11-18 17:59:49

+0

and here:http://stackoverflow.com/questions/3828982/xmlhttprequest-cannot-load-an-url-with-jquery – 2010-11-18 20:12:30

回答

1

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

1

您需要在同一个域上的服务器端代码来为您执行抓取。

+0

我对这个任务有什么是JS,没有更多。 – 2010-11-18 17:01:15

+3

@ den-javamaniac然后伤心地(或者高兴地说,如果你的意图是邪恶的话:)你是不幸的。 (除非服务器支持JSONP。) – Phrogz 2010-11-18 17:45:08

0

iframing in it?

<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> 
相关问题