Chrome 发送请求错误:TypeError:将循环结构转换为 JSON [英] Chrome sendrequest error: TypeError: Converting circular structure to JSON

查看:29
本文介绍了Chrome 发送请求错误:TypeError:将循环结构转换为 JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下...

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

However, my code never reaches "ZOMG HERE" but rather throws the following error while running chrome.extension.sendRequest

 Uncaught TypeError: Converting circular structure to JSON
 chromeHidden.JSON.stringify
 chrome.Port.postMessage
 chrome.initExtension.chrome.extension.sendRequest
 suggestQuery

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

Does anyone have any idea what is causing this?

推荐答案

表示你在请求中传递的对象(我猜是pagedoc)有循环引用,比如:

It means that the object you pass in the request (I guess it is pagedoc) has a circular reference, something like:

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

JSON.stringify 不能转换这样的结构.

JSON.stringify cannot convert structures like this.

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

N.B.: This would be the case with DOM nodes, which have circular references, even if they are not attached to the DOM tree. Each node has an ownerDocument which refers to document in most cases. document has a reference to the DOM tree at least through document.body and document.body.ownerDocument refers back to document again, which is only one of multiple circular references in the DOM tree.

这篇关于Chrome 发送请求错误:TypeError:将循环结构转换为 JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆