I am creating a JSON array from the presented data in the form, but this script is broken and cannot understand what is causing it!
Any ideas?
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");
The problem is with the declaration:
var Submission = {}; var Answer = {};
They must be such arrays that objects (hash) do not have push() defined
push()
var Submission = []; var Answer = [];
Source: https://habr.com/ru/post/1500384/More articles:getResourceAsStream returns null randomly and infrequently - javaMongoDB Update array element - arraysDeploying a TCP Server in Heroku - node.jsWhy do I sometimes get a βlockβ: deadlock (fatal) error detected? - gitReplace String values ββwith hash map value - javaWindows Phone 8 Page Life Cycle - windows-phoneIs there a non-mini version of JavaScript for the FireBase API? - luajava.lang.NoSuchMethodError: org.springframework.web.context.ConfigurableWebApplicationContext.setId (Ljava / lang / String;) V - javaMerge when merging sort without using temporary arrays - cIs there an available version of the Firebase v3 JS library with an incomplete / non-minified (debug) version? - javascriptAll Articles