Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
177
rated 0 times [  183] [ 6]  / answers: 1 / hits: 70280  / 12 Years ago, sat, april 21, 2012, 12:00:00

My overall goal is to get all some of all drop-downs on a page and send that to be processed by a php file.



Right now, the way I'm doing it in jQuery is making an overall schedule array and then adding each element to be updated to that array. So I have something like:



var schedule = [];
var data = {
'user_id' : '12',
'day_of_week' : 'Monday',
'when' : 'start',
'time' : '12 AM'
}
schedule.push(data);
var data = {
'user_id' : '13',
'day_of_week' : 'Tuesday',
'when' : 'end',
'time' : '12 AM'
}
schedule.push(data);
// schedule would have two objects in it


Obviously in loops and and stuff.



So, my schedule array has two objects in it, in this case.



Now, is it possible to use that schedule array as the ajax data? It doesn't work if I do something like:



$.ajax({
url: 'http://something.com/ajax',
data: schedule,
type: 'POST'
});


But if I instead change it to schedule[0] it works just fine, but only for the first thing in the schedule array, obviously.


More From » jquery

 Answers
6

Make sure you are using the correct version of jQuery. In earlier versions, you had to pass a sting; new versions use intelligent guess on the data variable. You can either explicitly tell jQuery that you're passing it a javascript object with the dataType parameter, or you can let jQuery figure it out.



Documentation



jQuery.ajax() - http://api.jquery.com/jQuery.ajax/


[#86089] Friday, April 20, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
byrondonavanc

Total Points: 675
Total Questions: 107
Total Answers: 105

Location: Peru
Member since Fri, Oct 14, 2022
2 Years ago
byrondonavanc questions
;