Wednesday 15 June 2011

php - how to get the value of multidimensional array pass from jquery and ajax? -



php - how to get the value of multidimensional array pass from jquery and ajax? -

i send multidimensional array ajax.js test1.php. not know how retrieve multidimensional array in test1.php. have found lots of examples did not work me.

ajax.js

answers = {}; answers[0] = {}; answers[0]['question_id'] = '12'; answers[0]['answer_id'] = '32'; $.ajax({ type: "post", url: 'test1.php', data: {answers: answers}, //datatype: "json", error: function(jqxhr, textstatus, errorthrown){ alert(errorthrown); }, success: function(data){ alert('success!'); } });

test1.php

$a=$_post['answers'][0]['answer_id']; echo "$a"; //display nothing, wish display '32' here

appreciate helps. thanks!

update: included library , ajax.js give me alert 'success'. not library problem. 1 time again helps!

try -

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script> answers = {}; answers[0] = {}; answers[0]['question_id'] = '12'; answers[0]['answer_id'] = '32'; $.ajax({ type: "post", url: 'test1.php', data: {answers: answers}, //datatype: "json", error: function(jqxhr, textstatus, errorthrown){ alert(errorthrown); }, success: function(data){ alert('success!'); } }); </script>

test1.php

<?php $a=$_post['answers'][0]['answer_id']; echo "$a hello"; //display nothing, wish display '32' here

php jquery arrays ajax

No comments:

Post a Comment