我正在从表单中提交的数据构建一个JSON数组,但是这个脚本正在破坏,无法弄清楚导致它的原因!
有什么想法吗?
Jquery的:
var canvas = [];
var Submission = {};
var Answer = {};
$('.question-holder > input').each(function(){
answer = $(this).val()
input_name = $(this).attr('name')
label = $(this).closest('li').find('label')
// Push everything into the questions array
Answer.push({
Answers: answer,
Input_Name: input_name,
Label: label
});
});
$('.submit-holder > input').each(function(){
answer = $(this).val()
input_name = $(this).attr('name')
label = $(this).closest('li').find('label')
Submission.push({
Question: label,
Input_Name: input_name,
Submitted_data: answer
});
});
canvas.push({
Submission: Submission,
Answers: Answer,
Motivation: $('.motivation').val()
});
json = JSON.stringify({json: canvas}, null, "\t");
答案 0 :(得分:2)
问题与声明有关:
var Submission = {};
var Answer = {};
它们应该是这样的数组,对象(哈希)没有定义push()
var Submission = [];
var Answer = [];