简体   繁体   English

SCRIPT5:IE9上的访问被拒绝

[英]SCRIPT5: Access is denied on IE9

I can't access a URL using this script on IE9. 我无法在IE9上使用此脚本访问URL。 In Chrome and on Firefox it works fine. 在Chrome和Firefox上运行正常。 When I debug ( F12 ) on IE9, I receive: 当我在IE9上调试( F12 )时,我收到:

SCRIPT5: ACCESS DENIED.

My function: 我的功能:

function NewPage2() {
    var xmlHttp;
    if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlHttp = new XMLHttpRequest();

    } else { // code for IE6, IE5
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlHttp.open("GET", "https://graph.facebook.com/oauth/access_token?client_id=" +
        '<%=ConfigurationManager.AppSettings["clientId"].ToString() %>' + 
        '&redirect_uri=' + <%=ConfigurationManager.AppSettings["redirectUrl"].ToString() %>' +
        '&state=' + document.getElementById('text').value + 
        '&client_secret=' + '<%=ConfigurationManager.AppSettings["client_secret"].ToString() %>' +
        '&code=' + getUrlVars2()["code"], false);
    xmlHttp.send(null);
    end(xmlHttp.responseText + "&userId=" + getUrlVars2()["state"]);
}

This happens when you try to access an ajax request from a different domain to your main page. 当您尝试从其他域访问主页的ajax请求时,会发生这种情况。 (In this case, you're accessing a URL from Facebook). (在这种情况下,您正在从Facebook访问URL)。

If you need to access a URL from a different domain, it is called a Cross Site Request. 如果您需要从其他域访问URL,则称为跨站点请求。 These are blocked by default because of the security implications, but it is still possible to do them with a bit more work. 由于安全方面的考虑,默认情况下会阻止它们,但是仍然可以做更多的工作。

It's pretty easy to do with jQuery. 使用jQuery非常容易。

The odd thing is that although you included jQuery in the tags on the question, your actual code isn't using jQuery at all -- in fact, the whole of the code you've provided would be a single line in jQuery, plus it would work with cross-site requests. 奇怪的是,尽管您在问题的标记中包括了jQuery,但是您的实际代码根本没有使用jQuery-实际上,您提供的整个代码在jQuery中仅一行,加上它可以处理跨站点请求。

You need to use an Ajax technique call JSONP, which you can find documented on the jQuery site here: http://api.jquery.com/jQuery.ajax/ 您需要使用一种称为JSONP的Ajax技术,您可以在以下jQuery网站上找到该文档: http : //api.jquery.com/jQuery.ajax/

The code would look something like this: 代码看起来像这样:

$.ajax({
  dataType: 'jsonp',
  jsonp: 'jsonp_callback',
  url: 'https://graph.facebook.com/......',
  success: function () {
    // do stuff
  },
});

hope that helps. 希望能有所帮助。

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

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