Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/419.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法在chrome扩展内发送jQuery Ajax HTTP请求_Javascript_Jquery_Ajax_Google Chrome_Google Chrome Extension - Fatal编程技术网

Javascript 无法在chrome扩展内发送jQuery Ajax HTTP请求

Javascript 无法在chrome扩展内发送jQuery Ajax HTTP请求,javascript,jquery,ajax,google-chrome,google-chrome-extension,Javascript,Jquery,Ajax,Google Chrome,Google Chrome Extension,我想在google chrome扩展中发送一个jQuery Ajax HTTP请求。我导入了jQuery库,并使用了以下代码: $.ajax({ method: "PUT", url: "https://spreadsheets.google.com/feeds/cells/"+id+"/od6/private/full/"+cell, headers: {'If-Match': '*'},

我想在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页面(导入了此javascript代码)时(作为单个HTML页面),我没有收到这条消息,我每次都成功了

为什么会发生这种情况?如何在分机内发送此请求


注意:我不使用XMLHttpRequest()的原因是,我必须在请求中单独发送标题和数据(这是google sheets api所需的
标记)。我不知道如何在XMLHttpRequest()中实现这一点。如果XMLHttpRequest()确实有效,请给我一个使用XMLHttpRequest()发送头和数据的代码示例。

在mainifest文件中尝试更改

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


在mainifest文件中,尝试更改

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


这是在内容脚本还是背景页面中?弹出窗口?您的清单文件是什么?不,弹出窗口上有一个按钮。一旦用户点击了这个按钮,一个新的HTML页面(我已经打包了扩展)就会在一个新的选项卡中弹出@ImanKView我的整个manifest.son文件在这个链接@epascarello中是在内容脚本还是背景页面中?弹出窗口?您的清单文件是什么?不,弹出窗口上有一个按钮。一旦用户点击了这个按钮,一个新的HTML页面(我已经打包了扩展)就会在一个新的选项卡中弹出@ImanKView我的整个manifest.son文件在此链接@epascarello