如何在谷歌浏览器应用程序上发布JSON

How to POST JSON on Google Chrome App?

本文关键字:程序上 JSON 应用程序 应用 谷歌浏览器      更新时间:2023-09-26

如何在Google Chrome App上webrequest POST JSON?也请举一个例子,因为我是谷歌浏览器应用程序的新手。

如果这是一个重复的任务,请评论答案链接。

谢谢。

它是XMLHttpRequest对象,与AJAX中的对象相同。请查看参考 Cross-Native XMLHttpRequest

下面是 w3c.org 的示例:

function log(message) {
  var client = new XMLHttpRequest();
  client.onreadystatechange = function() {
    // in case of network errors this might not give reliable results
    if(this.readyState == this.DONE)
      console.log("log entry sent with status: " + this.status);
  }
  client.open("POST", chrome.extension.getURL("/log"), true);
  client.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
  client.send(message);
}