【问题标题】:Access to restricted URI denied" code: "1012"访问受限 URI 被拒绝”代码:“1012”
【发布时间】:2012-02-22 10:54:36
【问题描述】:

我正在尝试使用 jquery 在间隔后 ping 服务器。我发现互联网上的 jquery ajax 函数为这么多人工作,但它抛出异常 “访问受限 URI 被拒绝”代码:Firefox 中的“1012”,IE 中的错误代码 0 和 www.google.com 的 404 Chrome。我不明白问题出在哪里。以下是我的代码。

<html>
<head>
    <title>Server availability</title>
    <script src="http://code.jquery.com/jquery-1.7.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">


        var req = function () {
            count = count + 1;
            var link = $('#testURL').val();
            $.ajax({
                url: testURL,
                success: function () {
                    $('#spnStatus').html($('#spnStatus').html() + '<br/><br/>' + link + ' Checked ' + count + ' times. Server available');
                },
                error: function (xhr, ajaxOptions, thrownError) {
                    //alert(xhr.status + "\n" + thrownError);

                    $('#spnStatus').html($('#spnStatus').html() + '<br/><br/>' + link + ' Checked ' + count
                    + ' times. Server not available. Error Code:' + xhr.status + "<br/> Exception:" + thrownError);
                }
            });
            //Call it again.
            setTimeout(function () {
                req();
            }, 5000);
        };
        var count = 0;
        $(document).ready(function () {
            req();
        });

    </script>
</head>
<body>
    <input id="testURL" type="text" value="http://www.google.com" /><br />
    <span id="spnStatus">Not checked yet.</span>
</body>
</html>

提前致谢。

【问题讨论】:

  • 是的,但它不能那样工作:S
  • 您不能使用 AJAX 访问来自其他域的页面,除非它们是 JSONP 类型的。因此,如果您无法将 JSONP 页面放在 other 域(因为您可能无法控制它),则只能使用服务器端代理(local) 检查另一个页面,然后你 AJAX 到那个本地代理 .. 阅读jquery-howto.blogspot.com/2009/04/… 了解更多信息..

标签: jquery


【解决方案1】:

Gaby aka G. Petrioli 谢谢你的第二条评论是我的答案。 :)

【讨论】:

    猜你喜欢
    • 2010-09-08
    • 1970-01-01
    • 1970-01-01
    • 2012-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-24
    • 2012-03-17
    相关资源
    最近更新 更多