phpjqueryarrays.post

passing an array to a .php file using post in jquery


I am trying to post an existing array in jquery using $.post to a evaluate.php page. I tried to serialize it and send it. But its not working. I get a internal server error. Can somebody suggest a method for me to post my array? Very much in need of help.

 <?php  
             function radioevaluation($qnum) {

              echo "<script> $(document).ready(function(){
                            var x= ".$qnum.";   
                        $('#q'+x+'verify').click(function(){

                                var answerarray = [];                           
                    answerarray['answer'] =$('input[name=q'+x+']:checked').val();

                            answerarray['qnum']= x;
                            var answer =jQuery.param(answerarray);

                            $.post('evaluate.php',answer,function(data){                        
                                var a= data;        
                                alert(a.result);    

                            }, 'json');

                        });
                    });</script>";
                }
?>

Solution

  • EDIT:

    Sorry I missed your second comment.

    I think you want to define answerarray not as an array but like so:

    var answerarray = {};