jquery未解决的TypeError("无访问权限")问题取决于浏览器导航

Dav*_*d M 12 javascript php ajax jquery

我试图研究这个,但我完全难过了.我认为这可能与同源策略有关,但我无法弄清楚它与我的代码有什么关系.

我有一个运行jquery和bootstrap的php站点,它在mysite/build.php呈现一个动态的Web表单.包含我的脚本调用的头部如下所示:

<head>
    <!-- jQuery -->
    <script src="https://code.jquery.com/jquery-3.1.0.min.js" integrity="sha256-cCueBR6CsyA4/9szpPfrX3s49M9vUU5BgtiJj06wt/s=" crossorigin="anonymous"></script>

    <!-- Bootstrap Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">        

    <!-- Bootstrap Latest compiled and minified JavaScript -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

    <!-- app CSS -->
    <link href="/css/styles.css" rel="stylesheet"/>

    <!-- Are-You-Sure dirty form checker -->
    <script src="/js/are-you-sure.js"></script>

    <!-- app JavaScript -->
    <script src="/js/build-edit-scripts.js"></script>

    <!-- obtain sheet data for edit mode -->
    <?php if (isset($items)): ?>
        <script type="text/javascript">
            var items = <?php echo json_encode($items) ?>; 
            var sheetinfo = <?php echo json_encode($sheetinfo) ?>;
            var slug = <?php echo json_encode($slug) ?>;
        </script>
    <?php endif ?>

    <!-- obtain single block and bullet elements for js -->
    <script> var blockHTML = <?php echo json_encode($blockhtml) ?>; var bulletHTML = <?php echo json_encode($bullethtml) ?>;</script>

    <title><?= (isset($sheetinfo)) ? "Edit: ".htmlspecialchars($sheetinfo['name']) : "Shopping List Generator"; ?></title>

</head>
Run Code Online (Sandbox Code Playgroud)

然后我的自定义javascript(build-edit-scripts.js)的开头如下所示

//execute when DOM fully loaded 
$(function() {

// enable areYouSure plugin to detect dirty form changes
$('#myform').areYouSure();

// mark form as dirty any time any text input changes
$(document).on('change', 'input:text', function() {
    $('#myform').addClass('dirty');
});

    // create empty array for existing slugs
    var slugs = [];

    // initiate ajax request to get dir listing of existing sheets
    $.ajax({

        url: "json-io.php",

        data: {
            purpose: "sheetlist"
        },

        type: "POST",

        dataType : "json"
    })

    // if successful
    .done(function(dirjson) {
            slugs = dirjson;
          })

    // if failure
    .fail(function( xhr, status, errorThrown ) {
            alert( "Server Error" );
            console.log( "Error: " + errorThrown );
            console.log( "Status: " + status );
            console.dir( xhr );
    });         

    // give focus to title field
    $("#title").focus();
Run Code Online (Sandbox Code Playgroud)

当我最初加载build.php,或者硬刷新它时,我没有问题.但是,每当我导航到外部站点,然后点击后退导航并返回到build.php时,我收到以下控制台错误:

未捕获的TypeError:无访问权限(@jquery-3.1.0.min.js:2)

然后是与不正确的jquery加载相关的问题

未捕获的错误:Bootstrap的JavaScript需要jQuery(@ bootstrap.min.js:6)

未捕获的ReferenceError:未定义jQuery(@ are-you-sure.js:192)

未捕获的ReferenceError:$未定义(@ build-edit-scripts.js:12)

从这里开始,我的JS其余部分都没有.我原本以为这可能是由于我的ajax请求有问题,但即使我完全删除了ajax请求,问题仍然存在.任何见解都会受到高度赞赏,因为我似乎无法针对问题发生的目标.谢谢.

use*_*039 10

碰到这个是因为我在使用链接中的后退按钮导航回来时,Chrome中的错误相同(或者有).导航后加载页面并且任何脚本尝试访问窗口对象时,都会发生此错误.

这个页面是对此错误消息的两个引用之一("Uncaught TypeError:no access")我可以在网络上的任何地方找到 - 另一个是Chrome错误报告,据说一年前修复了.不要认为它与jQuery(我们的纯javascript)有任何关系,但不知道是什么原因导致它或它意味着什么,它似乎是一个非常模糊的错误.重新启动浏览器后,此错误不再可重现,但已多次出现.一旦脚本代码尝试读取窗口对象的任何窗口属性,就会发生这种情况.如果有人知道这个错误意味着什么以及可能导致什么,那就发布这个.

  • 嗨,我想我会说在非常特殊的情况下我看到这个太有趣了.我有一个简单的jQuery脚本,可以在页面上动态编写href链接,如果其中一个是"http://google.com",那么在用户点击链接并导航到谷歌然后点击回Chrome之后(工作正常)边缘)发生此错误并且页面上的所有JavaScript都失败(window object == null).有趣的是,DOESNT发生在其他链接上,例如http://microsoft.com(和其他一些我尝试过的).所以听起来Chrome中的一个错误与某些网站的工作方式有关. (3认同)

Ans*_*elm 1

我唯一能想到的是你的 CORS 配置不正确,尽管看起来很好,或者当你尝试访问 jQuery 时你的文档没有完全加载,看起来你的代码应该加载得很好。

您确定需要integrity="sha256-cCueBR6CsyA4/9szpPfrX3s49M9vUU5BgtiJj06wt/s=" crossorigin="anonymous"在脚本包含的末尾添加标签吗?这些可能不是正确的参数,并且可能会导致一些冲突。