Javascript XMLHttpRequest无法加载。否';访问控制允许原点';请求的资源上存在标头。因此,不允许“源”访问

Javascript XMLHttpRequest无法加载。否';访问控制允许原点';请求的资源上存在标头。因此,不允许“源”访问,javascript,html,google-chrome,Javascript,Html,Google Chrome,我想通过发送url、用户名和密码登录到一个网站,但发送类似上述XMLHttpRequest的错误无法加载https://example.org。请求的资源上不存在“Access Control Allow Origin”标头。因此,不允许访问源“” <!DOCTYPE html> <html> <head> <title>build</title> </head> <bo

我想通过发送url、用户名和密码登录到一个网站,但发送类似上述XMLHttpRequest的错误无法加载
https://example.org
。请求的资源上不存在“Access Control Allow Origin”标头。因此,不允许访问源“”

    <!DOCTYPE html>
<html>
    <head>
        <title>build</title>
    </head>
    <body>
    <script type="text/javascript">

        if (window.XMLHttpRequest)
        {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        }
        else
        {// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }


        xmlhttp.onreadystatechange=function()
        {
            if (xmlhttp.readyState===4 && xmlhttp.status===200)
            {
                document.getElementById("test1").value=xmlhttp.responseText;
            } else
                {
                     alert('Panel not communicating.Reason: '+xmlhttp.status);
                }
        };
        xmlhttp.open("POST","https://bitbucket.org/account/signin/?next=/xyz/xyz.git",true,"username","password");
        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlhttp.setRequestHeader("Access-Control-Allow-Origin","*");
        xmlhttp.setRequestHeader("Access-Control-Allow-Credentials",true);
        xmlhttp.setRequestHeader("Access-Control-Allow-Methods","POST");
        xmlhttp.send();

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

建造
if(window.XMLHttpRequest)
{//IE7+、Firefox、Chrome、Opera、Safari的代码
xmlhttp=新的XMLHttpRequest();
}
其他的
{//IE6、IE5的代码
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数()
{
if(xmlhttp.readyState==4&&xmlhttp.status==200)
{
document.getElementById(“test1”).value=xmlhttp.responseText;
}否则
{
警报(“面板不通信。原因:”+xmlhttp.status);
}
};
open(“POST”https://bitbucket.org/account/signin/?next=/xyz/xyz.git,true,“用户名”、“密码”);
setRequestHeader(“内容类型”,“应用程序/x-www-form-urlencoded”);
setRequestHeader(“访问控制允许源代码”、“*”);
setRequestHeader(“访问控制允许凭据”,true);
setRequestHeader(“访问控制允许方法”、“POST”);
xmlhttp.send();
任何人请帮助我。提前感谢。

“访问控制允许来源”策略是跨域HTTP请求中使用的一种安全方式。 它的想法是让“每个人”从您的服务器中提取数据,以保证数据的安全。
您可以在此处阅读更多内容:。

谢谢@Aviad,但它出现了一个安全错误“跨源请求被阻止:同一源策略不允许读取处的远程资源。这可以通过将资源移动到同一域或启用CORS来解决。”我如何解决它。