【问题标题】:Cannot send jQuery Ajax HTTP Request inside chrome extension无法在 chrome 扩展中发送 jQuery Ajax HTTP 请求
【发布时间】:2015-12-01 04:32:27
【问题描述】:

我想在 google chrome 扩展中发送一个 jQuery Ajax HTTP 请求。我已经导入了 jQuery 库,我使用了以下代码:

    $.ajax({
            method: "PUT",
            url: "https://spreadsheets.google.com/feeds/cells/"+id+"/od6/private/full/"+cell,
            headers: {'If-Match': '*'},
            contentType: 'application/atom+xml',
            data: data
        }).done(function(msg) {
            alert("Data Saved: "+JSON.stringify(msg));
        }).fail(function(e){
            alert("There was a problem!\n"+JSON.stringify(e));
        })

但每当我尝试时,它都会向我显示一条消息:

    There was a problem!
    {"readyState":0,"status":0,"statusText":"error"}

但是当我在扩展程序之外(作为单个 html 页面)运行相同的 HTML 页面(已导入此 javascript 代码)时,我没有收到此消息,我每次都成功。

为什么会发生这种情况?如何在我的扩展程序中发送此请求?

注意:我不使用 XMLHttpRequest() 的原因是因为我必须单独发送请求头和数据(这是 google sheet api 所需的 <entry>...</entry> 标记)。我不知道如何在 XMLHttpRequest() 中做到这一点。如果 XMLHttpRequest() 有效,请给我一个使用 XMLHttpRequest() 发送标头和数据的代码示例。

【问题讨论】:

  • 是在内容脚本还是背景页面中?弹出窗口?
  • 你的清单文件是什么?
  • 不,弹出窗口上有一个按钮。用户单击此按钮后,一个新的 HTML 页面(我已与扩展程序一起打包)会在新选项卡中弹出。 @ImanK
  • 在此链接docs.google.com/document/d/…@epascarello 上查看我的整个 manifest.son 文件

标签: javascript jquery ajax google-chrome google-chrome-extension


【解决方案1】:

在你的 mainifest 文件中尝试更改

"permissions": [
    "storage",
    "activeTab",
    "tabs",
    "https://ajax.googleapis.com/"
  ]

"permissions": [
    "storage",
    "activeTab",
    "tabs",
    "https://ajax.googleapis.com/",
    "https://*.google.com/"
  ]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-26
    • 1970-01-01
    • 2016-09-26
    • 2014-10-13
    相关资源
    最近更新 更多