小编dil*_*ger的帖子

Chrome扩展帖子请求不发送数据

第一次使用网站提问.我是Chrome扩展程序的新用户,所以我确定我犯了一些愚蠢的错误.我提前道歉.

我正在尝试获取当前选项卡的URL并将其POST到URL,然后将其接收并将其推送到数据库中.就像我自己的个人书签服务.我已经尽可能多地进行了调试,数据正在一直到我发送XHR请求的地方..但是当我在服务器端脚本上回显它时,数据不会出现.我确认它正在击中我的URL因为我是控制台记录输出...但是再次没有传递数据.

BACKGROUND.JS

chrome.runtime.onMessage.addListener(function(request, sender, callback) {
    if (request.action == "xhttp") {
        var xhttp = new XMLHttpRequest();
        var method = request.method ? request.method.toUpperCase() : 'GET';
        xhttp.open(method, request.url, true);
        xhttp.send(request.data);
        xhttp.onload = function() {
            callback(xhttp.responseText);
        };
        return true
    }
});
Run Code Online (Sandbox Code Playgroud)

的manifest.json

{
  "name": "bookmarker",
  "version": "0.0.1",
  "manifest_version": 2,
  "description": "POSTIN BOOKMARKS!",
  "homepage_url": "URL",
  "icons": {
    "16": "icons/icon16.png",
    "48": "icons/icon48.png",
    "128": "icons/icon128.png"
  },
  "permissions": [
    "contentSettings",
    "cookies",
    "tabs",
    "geolocation",
    "http://*/*"
  ],
  "content_scripts": [
    {
      "js": ["contentscript.js"],
      "matches": ["http://*/*"]
    }
  ],
  "browser_action": { …
Run Code Online (Sandbox Code Playgroud)

javascript post xmlhttprequest google-chrome-extension

3
推荐指数
1
解决办法
6691
查看次数