【发布时间】:2012-01-07 20:06:57
【问题描述】:
我的 AJAX 请求遇到了一些问题。 问题在于名为 html 的 JSON 对象。
AJAX 请求:
$.ajax({
url : 'index',
type : 'POST',
dataType : 'json', // Makes no difference
data : {
method : 'saveModule',
html : content
},
success : function(i){
console.log(i);
}
})
我知道这是关于 html JSON 对象的,因为如果我删除它,请求就会成功。
这就是 firebug 的 console.log() 的样子;
对象存储在 [ ] 中,这正常吗?
[Object { name="Home", link="/home"}, Object { name="Work", link="/work", childs=[3]}, Object { name="Contact", link="/contact", childs=[2]}]
孩子也是 JSON 对象。
请帮忙,我快疯了!
我在使用 Web 控制台时遇到的错误:
[11:58:47.215] uncaught exception: [Exception... "Could not convert JavaScript argument" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: http://localhost/mcms/htdocs/templates/resources/js/jquery-1.6.3.min.js :: <TOP_LEVEL> :: line 5" data: no]
content var 由以下内容构成:
var content = mcms.module.analyse(obj); // obj is a dom element, in this case a UL with sub ULs inside LIs
函数本身:
analyse : function (that) {
return $(that).children('li').map(function() {
var b = {
name: $(this).children('a').text(),
link: $(this).children('a').attr('href')
};
if ($(this).children('ul').size() > 0) {
b.childs = mcms.module.analyse($(this).children('ul'));
}
return b;
});
}
【问题讨论】:
-
content变量在哪里设置? -
当您说“这就是 firebug 的 console.log() 的样子”时,您是在谈论 ajax 成功处理程序中
console.log(i)语句的输出吗?如果不是,那是什么? -
是的,就是这样,但只有重要的部分,内容变量
标签: javascript jquery json