简体   繁体   English

在 chrome 扩展的 js 中包含 jquery 库

[英]includes the jquery library in js of a chrome extension

I'm trying to run this ajax work:我正在尝试运行此 ajax 工作:

    $ (document).ready(function() {
 $.ajax({
    url: 'sendvalue.php',
    type: 'POST',
    dataType:'json', 
    data: ({cookievalue: cookie.value}),
    success: function(data) {
       console.log(data);
    }
  });
});

But, rightfully so, since I have not put in the inclusion of the jquery ajax library (I cannot include because the script is in a js file and not in the index), I get this error:但是,这是正确的,因为我没有包含 jquery ajax 库(我不能包含,因为脚本在 js 文件中而不是在索引中),我收到此错误:

index.html:1 Error handling response: ReferenceError: $ is not defined at chrome-extension://ebekofgaihoolgeccoalidkchcofecbd/main.js:9:4 index.html:1 错误处理响应:ReferenceError: $ is not defined at chrome-extension://ebekofgaihoolgeccoalidkchcofecbd/main.js:9:4

I tried to auto-include the library but I get another error:我尝试自动包含该库,但出现另一个错误:

main.js:3 Refused to load the script 'https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js' because it violates the following Content Security Policy directive: "script-src 'self' blob: filesystem:". main.js:3 拒绝加载脚本“https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js”,因为它违反了以下内容安全策略指令:“script- src 'self' blob:文件系统:"。 Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.请注意,'script-src-elem' 没有明确设置,因此 'script-src' 用作后备。

How can I solve?我该如何解决?

Please Remove JS code from your main index file and add new js file and paste code there.请从您的主索引文件中删除 JS 代码并添加新的 js 文件并将代码粘贴到那里。 All js and css files included in your index file And use functionality I think is work.索引文件中包含的所有 js 和 css 文件并使用我认为可行的功能。

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

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