I've written a Chrome Extension for my library. It makes an AJAX call to api.library.edu (school's library).

我为我的图书馆编写了Chrome扩展程序。它向api.library.edu(学校的图书馆)发出AJAX调用。

My extension uses jQuery and my code looks like this:

我的扩展使用jQuery,我的代码如下所示:

$.get("http://api.library.edu/?period=1month", function (data) {
    // process data
});

When I load my Extension, it makes the AJAX call and I get data back.

当我加载我的扩展时,它会进行AJAX调用并返回数据。

Right now I give absolutely no permissions to my extension (permissions is []).

现在我完全没有权限扩展我的权限(权限是[])。

Is my extension going to work when I publish it? Shouldn't it require special permissions to make AJAX calls with jQuery?

我发布时我的扩展程序是否正常工作?它不应该需要特殊权限来使用jQuery进行AJAX调用吗?

Thanks! I'm just making sure I wrote my extension correctly.

谢谢!我只是确保我正确地写了我的扩展程序。

1 个解决方案

#1


3

Your extension does not need any additional permissions to make AJAX calls from within the same origin. However, if api.library.edu does not set the proper CORS headers, you may need to request cross-origin permission for that domain:

您的扩展程序不需要任何其他权限即可在同一来源中进行AJAX调用。但是,如果api.library.edu未设置正确的CORS标头,您可能需要为该域请求跨域权限:

{
  "name": "My extension",
  ...
  "permissions": [
    "http://api.library.edu/"
  ],
  ...
}

From Google's Docs:

来自Google的文档:

Each running extension exists within its own separate security origin. Without requesting additional privileges, the extension can use XMLHttpRequest to get resources within its installation.

每个运行的扩展都存在于其自己独立的安全源中。在不请求其他权限的情况下,扩展可以使用XMLHttpRequest来获取其安装中的资源。

...

...

By adding hosts or host match patterns (or both) to the permissions section of the manifest file, the extension can request access to remote servers outside of its origin.

通过将主机或主机匹配模式(或两者)添加到清单文件的权限部分,扩展可以请求访问其源外的远程服务器。

If your extension is already working though, that would lead me to believe that the library API already has cross-domain headers set, and that you will not need any additional permissions.

如果您的扩展程序已经正常工作,那么这会让我相信库API已经设置了跨域标头,并且您不需要任何其他权限。

更多相关文章

  1. 字符串压缩 牛客网 程序员面试金典 C++ Python
  2. Pycharm 运行跳一跳程序
  3. [Python]—Linux Server 系统监控程序
  4. 在两台服务器上有效地在两个Django应用程序之间进行通信(多租户)
  5. 高级程序员装逼指南
  6. res.partner上`write`的高级访问权限
  7. 购物车程序练习
  8. 如何停止Py_Initialise应用程序的崩溃?
  9. Python语言的特点、程序设计基本方法

随机推荐

  1. 基于树莓派的 Android(安卓)Things 开发
  2. android关于百度地图显示网格问题
  3. Android系列之网络(二)----获取HTTP请求头
  4. Android运行机制
  5. Mars Android视频教程完整版高清在线观看
  6. Android进阶-Android系统信息与安全机制
  7. ProgressBar(进度条) 分类 Android 基础
  8. Android 属性总结
  9. android 中文 api (64) ―― Scroller
  10. Android Studio 4.0 - 创建新项目