【问题标题】:XMLHttpRequest Open Access DeniedXMLHttpRequest 打开访问被拒绝
【发布时间】:2016-02-12 20:05:04
【问题描述】:

我试图在我的 javascript 代码中调用 xmlhttprequest 上的 open,但我得到一个异常“访问被拒绝”。

这是我的代码:

<script type="text/javascript">
    function doFunction() {
        alert("hi");
        xhr = new XMLHttpRequest();
        if (window.XMLHttpRequest) {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xhr = new XMLHttpRequest();
        } else {
            // code for IE6, IE5
            xhr = new ActiveXObject("Microsoft.XMLHTTP");
        }
        var url = "https://localhost:1234/test/pi/testing/operation";
        try{
            xhr.open("POST", url, true);
        } catch(err) {
            alert(err.message);
        }
        xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
        xhr.onreadystatechange = function () {
            if (xhr.readyState == XMLHttpRequest.DONE) {
                alert(xhr.responseText);
            }
        }
        var testText = document.getElementById("test").value;
        var jsonObject = { Status: "1", ErrorList: "", test: testText, Price: "" };
        var data = JSON.stringify(jsonObject);
        xhr.send(data);
    }
</script>

页面本身在 localhost:8080 的 IIS 上运行,我正试图在 localhost:1234 上调用我的 wcf 服务。 我将https://localhost 添加到我的受信任网站但仍然无法正常工作,这是为什么呢?

谢谢;)

【问题讨论】:

    标签: javascript exception xmlhttprequest access-denied


    【解决方案1】:

    http://localhost 添加到我信任的站点并开始工作。 这个问题和这个答案适用于 IE 10

    【讨论】:

      猜你喜欢
      • 2014-12-22
      • 2012-07-26
      • 1970-01-01
      • 2015-01-31
      • 2015-01-09
      • 2014-05-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多