【问题标题】:insecure script when running a $.getJSON with jasmine使用 jasmine 运行 $.getJSON 时脚本不安全
【发布时间】:2018-08-04 03:28:59
【问题描述】:

我正在学习 jasmine,现在我正在尝试测试 $.getJSON 以使用 github API 获取 github 用户名。这是我正在运行的代码:

index.html:

    <html lang="en">
    <head>
     <meta charset="UTF-8">
     <title>Jasmine Tests</title>
      <link rel="stylesheet" 
      href="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.6.2/jasmine.css">
     </head>
    <body>
    <script
     src="http://code.jquery.com/jquery-3.3.1.min.js"
     integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
     crossorigin="anonymous"></script>
     <script 
    src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.6.2/jasmine.js">
     </script>
     <script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.6.2/jasmine-
     html.js"></script>
     <script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.6.2/boot.js">
    </script>
   <script type="text/javascript" src="test.js"></script>
     </body>
    </html>

test.js:

    function getUserInfo(username){
      return $.getJSON('https://api.github.com/users/' + username);
      //remember that all jquery ajax methods return a promise!
   }

describe("#getUserInfo", function(){
          it("returns the correct name for the user", function(done){
            getUserInfo('elie').then(function(data){
              expect(data.name).toBe('Elie Schoppik');
              done(); //invoke to make sure the test does not timeout
            });
      });
});

我在 cloud9 上运行并收到以下错误:

混合内容:“https://preview.c9users.io/pvanny1124/web-dev-bootcamp-1/Jasmine/index.html?_c9_id=livepreview12&_c9_host=https://ide.c9.io”处的页面通过 HTTPS 加载,但请求了不安全的脚本“http://code.jquery.com/jquery-3.3.1.min.js”。此请求已被阻止;内容必须通过 HTTPS 提供。

我能做什么?提前谢谢你!

【问题讨论】:

    标签: javascript unit-testing asynchronous jasmine


    【解决方案1】:

    通过 HTTPS 加载所有引用。将此行更改为使用 HTTPS。

    <script
      src="https://code.jquery.com/jquery-3.3.1.min.js"
      integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
      crossorigin="anonymous"></script>
    

    【讨论】:

    • 乐于助人。如果此答案或任何其他答案解决了您的问题,请将其标记为已接受。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-01
    • 1970-01-01
    相关资源
    最近更新 更多