おはようございます!オブジェクトリテラルをオブジェクト内の配列に挿入する
var persons = {};// I want all the objects in the array to be inserted here so that I can stringify it and send via Ajax
var array = [];// where I store the object literals
var courses = {};
course['name'] = $('#course').val();
array.push(courses);
var students = {};
students['first'] = $('#first_name').val();
students['last'] = $('#last_name').val();
students['age'] = $('age').val();
array.push(courses);
// I tried this after the help I got this morning but it does not create multiple objects. When there are many successive values, the data sent is empty
var persons = {
courses: {
name: $('#course').val(),
},
students: {
name: $('#first_name').val(),
last: $('#last_name').val(),
age: $('#age').val(),
},
};
誰もが、私はいくつかの学生を作成する方法を知っているし、当然と同じオブジェクトでそれらを持っていないしてください は、私は、フォームの値からオブジェクトリテラルを生成し、次のように私は、配列に格納します名?
を、なぜだけではなく、' JSON.stringify({[] }) '? – eisbehr
まず、 "course ['name'] = $( '#course')。val();" "コース['name'] = $( '#コース')。val();" – Arnab003