Passing multi dimensional array to PHP with jQuery and AJAX -
i've got jquery code:
$(document).ready(function() { answers = new array(); answers[0] = new array(); answers[0]['question_id'] = 12; answers[0]['answer_id'] = 32; answers[1] = new array(); answers[1]['question_id'] = 55; answers[1]['answer_id'] = 132; answers[2] = new array(); answers[2]['question_id'] = 987; answers[2]['answer_id'] = 1112; $.ajax({ type: "post", url: "collect.php", data: {answers: answers}, datatype: "json", beforesend:function(){ // before sending request server }, error: function(jqxhr, textstatus, errorthrown){ alert(errorthrown); }, success: function(data){ alert('success!'); } }); });
now, should work? according i've found when looking code examples should. problem is, have no idea how collect data in php file. mean, it's $_post[], what? how collect $result[0]['question_id'] , other data?
thanks lot in advance,
carl c. carlsson
you're never populating arrays inside of answers array data, length still 0 because you're using string indexes rather int indexes. want objects stored in array.
answers[0] = {}; answers[0]['question_id'] = 12; answers[0]['answer_id'] = 32;
Comments
Post a Comment