简体   繁体   English

跨域jQuery Popup POST

[英]Cross Domain jQuery Popup POST

I'm trying to make a cross domain POST using the following jQuery popup. 我正在尝试使用以下jQuery弹出窗口进行跨域POST。 IE gives me permission denied on Line 19 of jquery.min.js. IE在jquery.min.js的第19行拒绝了我的权限。 Please note that I have the following script running on www.mysite.com and I'm trying to post the data to www.google.com for example. 请注意,我在www.mysite.com上运行了以下脚本,例如,我试图将数据发布到www.google.com。 Thus making a cross domain post. 从而进行跨域发布。 I assume this is why IE is giving me permission denied. 我认为这就是IE给我拒绝权限的原因。 I know there should be a solution to create a hidden iframe but I have no idea how to implement this in my code. 我知道应该有一种创建隐藏的iframe的解决方案,但是我不知道如何在我的代码中实现这一点。 Some examples would be greatly appreciated. 一些例子将不胜感激。 Thanks in advance! 提前致谢!

<html>
<head>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/smoothness/jquery-ui.css" type="text/css" />
<style type="text/css">
#register { display: none; }
.ui-dialog { font-size: 10px; }
.ui-dialog .ui-dialog-titlebar-close { visibility: hidden; }
</style>
</head>
<body>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/jquery-ui.min.js"></script>
<script type="text/javascript">

function loadpopup(){

function Init() 
{
jQuery('#register').dialog({ width: 400, resizable: false, buttons: { "Continue": function() {
        if (jQuery("#email").val().length < 3) 
        {
            alert('Please enter your email address to continue.');
            jQuery("#email").focus();
        }
        else 
        {
            jQuery("#email_2").val(jQuery("#email").val());
            $.post("http://google.com/register.php", $("form[name='registerform']").serialize());
            jQuery('#register').dialog('close')}
    } 
}, closeOnEscape: false, modal: true, show: 'slide' });
}
jQuery(document).ready(Init);
}

loadpopup();

</script>
<div id="register">
<form>
<center>
<table><tbody>
<tr><td align="center" style="text-align: center; font-size: 10px; background: #FFFFFF;">
<br><h3>Register</h3>
  </td></tr>
<tr><td align="left" style="text-align: justify; font-size: 11px; background: #FFFFFF;">
Please enter your email address to continue.</br></br>
  </td></tr>
</tbody></table></center>
<center>
<div>
    <table>
        <tbody>
            <tr><td align="left" style="font-size: 12px; background: #FFFFFF;"><b>Email:</b></td><td align="left" style="background: #FFFFFF; font-size: 11px;"><input type="text" id="email" name="email" maxlength="26"/></td></tr>
        </tbody>
    </table>
</div>
</form>
</center>
</div>
<form name="registerform" action="http://google.com/register.php" method="post">
<input type="hidden" name="email_2" id="email_2" />
</form>
</body>
</html>

You are posting via XHR to a different domain. 您正在通过XHR发布到其他域。 You can't do that because of same origin policy . 由于相同的原产地政策 ,您不能这样做。

Instead, build the form and then call submit() on it. 相反,构建表单,然后在其上调用submit()

The way you are doing it now, Google is returning 405 Method Not Allowed which could be returned for a number of reasons. Google现在的操作方式是,返回405 Method Not Allowed ,出于多种原因,可能会返回该405 Method Not Allowed

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

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