javascript - Passing associative array through AJAX to PHP -
I am trying to pass it through AJAX in PHP scripts:
Var Reply = {}; For (x = 0; x & lt; allAnswers.length; x ++) {answers.x = new array (); Answers.x ['id'] == allAnswers [x] ['id']; Answers.x ['val'] = $ ("# field_" + x) .val (); } Var data = {}; Data.id = question [QID] ['id']; Data ['answer'] answer =; $ .post ('index.php', data); PHP print_r ($ _ POST) is set , and it is output:
North [object Object] ID 3 What has happened to me?
Edit: To change the code to use an array, that is:
var answers = new array (); For (x = 0; x & lt; allAnswers.length; x ++) {answer [x] = new array (); Answer [x] ['id'] = allAnswers [x] ['id']; Answer [x] ['val'] = $ ("# field_" + x) .val (); } Var data = {}; Data.id = question [QID] ['id']; Data ['answer []'] answer =; $ .post ('index.php', data); This print_r returns:
array ([ID] => 3 [answers] => array ([0] = &
< p> If you're going to repeat again answers.x from again, so you only the last one are going to get. X is the actual variable name and that he does not value you're thinking, "All Answars have" Try a double equal on the line: var Reply = New Array (); for (x = 0; x & lt; allAnswers.length; x ++) {Reply [X] = new array (); answer [x] ['id'] = all greetings [x] ['id']; answer [x] ['val'] = $ ("# field_" + x) Val ();}
Comments
Post a Comment