Jquery POST reporting未定义,JSON解析导致语法错误
这个想法相当简单,我们有一个灰尘模板创建复选框和一些静态复选框Jquery POST reporting未定义,JSON解析导致语法错误,jquery,json,node.js,dust.js,Jquery,Json,Node.js,Dust.js,这个想法相当简单,我们有一个灰尘模板创建复选框和一些静态复选框 <div class="span10"> <table class="table table-condensed"> <caption class="pull-left">Favorite Cuisines:</caption> <input type="hidden" id
<div class="span10">
<table class="table table-condensed">
<caption class="pull-left">Favorite Cuisines:</caption>
<input type="hidden" id="myArray" />
<tbody>
<tr>
{#data.cuisines}
<td>
<label class="checkbox inline">
<input type="checkbox" name="cuisineFavorites" value="{_id}">{cuisineName}
</label>
</td>
{/data.cuisines}
</tr>
<tr>
<td>
<label class="checkbox inline">
<input type="checkbox" name="cuisineFavorites" value="name"> blank
</label>
</td>
<td>
<label class="checkbox inline">
<input type="checkbox" name="cuisineFavorites" value="american"> American
</label>
</td>
<td>
</div>
{@eq key="userProfile" value=prtName}
<script type="text/javascript">
var selectedCuisines = [];
function addCuisine(cuisine) {
if ($.inArray(cuisine, selectedFavorites) < 0) {
selectedCuisines.push(cuisine);
selectedCuisines.sort();
}
$("#myArray").val("[" + selectedCuisines.join() + "]");
}
function removeCuisine(cuisine) {
var pos = $.inArray(cuisine, selectedCuisines);
if (pos > 0) {
selectedCuisines.splice(pos, 1);
selectedCuisines.sort();
}
$("#myArray").val("[" + selectedCuisines.join() + "]");
}
$('input[name^=cuisine]').on("click", function(e) {
if (this.checked === true) {
addCuisine(this.value);
} else {
removeCuisine(this.value);
}
});
</script>
{/eq}
}
请帮助,不知道为什么它是未定义的,让JSON.parse工作了几次,即使它仍然说未定义发布了一个示例输出
SyntaxError:exports.createProfile的Object.parse(本机)处出现意外标记u
它在这里工作
Model: {"title":"User Profile","prtName":"userProfile","user":{"_id":"532b781934
fa1a7411000003","__v":0,"authToken":"","salt":"1387859137798","hashed_password":
"e704f5c86a696a828fbb976446ee1243690b8917","provider":"local","username":"dw","g
ivenName":"dw","familyName":"dw"},"data":{"cuisines":[{"_id":"532a4d281053cd042c
000002","__v":0,"cuisineName":"American"},{"_id":"532a5c591053cd042c000003","__v
":0,"cuisineName":"Comfort Food"},{"_id":"532a5c5e1053cd042c000004","__v":0,"cui
sineName":"Indian"},{"_id":"532a5c681053cd042c000005","__v":0,"cuisineName":"Med
iterranean"},{"_id":"532a5c701053cd042c000006","__v":0,"cuisineName":"Portuguese
"},{"_id":"532a5c791053cd042c000007","__v":0,"cuisineName":"Argentinian"}]}}
获取/用户/配置文件/创建200 459ms
未定义
打印一些东西
保存配置文件:{u userId:532b781934fa1a7411000003,
_识别号:532b781f34fa1a7411000004,
美食最爱:
[532a4d281053cd042c000002,
532a5c591053cd042c000003,
532a5c5e1053cd042c000004],
特殊数据集:[],
食品:,
officePhone:“”,
用户标题:'}
收藏夹[“532a4d281053cd042c000002”、“532A5C5951053CD042C000003”、“532a5c5e1053cd0”
42c000004“]
但通常只有指纹
未定义的打印内容,然后发生上述错误。我最近更新了我安装的klei dust,但这不会影响JSON,不要麻烦使用这种方法跨任何对象发送数据数组。我记得post是如何工作的。Name=本例中的菜系收藏夹对应于每个复选框。“发送为邮件”时选中的任何复选框都将放入名为“收藏夹”的数组中。 在这种情况下,当我们创建一个新的配置文件并将req.body设置为该配置文件时,该配置文件会将cuisineFavorites设置为上一页上选择的任意选项
Model: {"title":"User Profile","prtName":"userProfile","user":{"_id":"532b781934
fa1a7411000003","__v":0,"authToken":"","salt":"1387859137798","hashed_password":
"e704f5c86a696a828fbb976446ee1243690b8917","provider":"local","username":"dw","g
ivenName":"dw","familyName":"dw"},"data":{"cuisines":[{"_id":"532a4d281053cd042c
000002","__v":0,"cuisineName":"American"},{"_id":"532a5c591053cd042c000003","__v
":0,"cuisineName":"Comfort Food"},{"_id":"532a5c5e1053cd042c000004","__v":0,"cui
sineName":"Indian"},{"_id":"532a5c681053cd042c000005","__v":0,"cuisineName":"Med
iterranean"},{"_id":"532a5c701053cd042c000006","__v":0,"cuisineName":"Portuguese
"},{"_id":"532a5c791053cd042c000007","__v":0,"cuisineName":"Argentinian"}]}}