javascript - Chrome 发送请求错误 : TypeError: Converting circular structure to JSON

标签 javascript json google-chrome google-chrome-extension

我有以下...

chrome.extension.sendRequest({
  req: "getDocument",
  docu: pagedoc,
  name: 'name'
}, function(response){
  var efjs = response.reply;
});

它调用以下..

case "getBrowserForDocumentAttribute":
  alert("ZOMG HERE");
  sendResponse({
    reply: getBrowserForDocumentAttribute(request.docu,request.name)
  });
  break;

但是,我的代码从未到达“ZOMG HERE”,而是在运行 chrome.extension.sendRequest

时引发以下错误
 Uncaught TypeError: Converting circular structure to JSON
 chromeHidden.JSON.stringify
 chrome.Port.postMessage
 chrome.initExtension.chrome.extension.sendRequest
 suggestQuery

有人知道是什么原因造成的吗?

最佳答案

表示你在请求中传入的对象(我猜是pagedoc)有一个循环引用,类似于:

var a = {};
a.b = a;

JSON.stringify 不能像这样转换结构。

注意:DOM 节点就是这种情况,它们具有循环引用,即使它们没有附加到 DOM 树。每个节点都有一个 ownerDocument,它在大多数情况下引用 documentdocument 至少通过 document.body 引用 DOM 树,而 document.body.ownerDocument 引用回 document 再次,这只是 DOM 树中多个循环引用中的 一个

关于javascript - Chrome 发送请求错误 : TypeError: Converting circular structure to JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4816099/

相关文章:

javascript - 使用 Javascript SDK 在启动时关联 ElasticIP

javascript - 如何更改 Mapbox GL JS 中多边形工具上的悬停文本?

javascript - 如何在 html 表格中显示 JSON 数据

php - 在 JSON 中添加其他对象

html - 在 chrome 中填充,但在 firefox 或 ie 中填充

javascript - 加载更多按钮脚本: image instead of text

javascript - 将 json 对象保存为文本文件

java - 如何从 Android 中的 MainActivity 调用静态方法中的内容

android - 在 Android/Chrome 中查看 PDF

google-chrome - chrome 26.0.1410.43 中与旧版本的渲染差异