Passing results from PHP class to AJAX and back to the calling script -


i have class returns set of data database. class called ajax , results need returned index.php can format , display results in table format.

problem: i'm unable return results throug ajax , php variable. can provide appreciated.

<php class questions  {  public function displayquestions()    {         return $this->questionarray;       } // contains set of data db } ?> 

return dataset class , pass $var can format data display

index.php:

<html> <body> <div id="questiondev" ><?php $var[] = returned ajax ?> </div>     <div id="questionbutton">    <form method="post" name="form_questions" action="">       <textarea name="saveqa"  id="saveqa"></textarea>        <button class="btn_save" id ="btn_save" name="btn_save">ask</button>    </form> </div>       <script src="http://code.jquery.com/jquery-latest.js"></script>         <script>                      $(document).ready(function() {            $('#btn_save').on('click', function() {            $.ajax({             type: "post",             cache: false,              url: "testdata.php",             datatype: "json",             success:function(info){             $('#questiondev').html(info[0]);             console.log(" reponse :"+ info);             }          });         });           $('#btn_save').trigger("click");          });                           </script>  </body> </html> 

add

data:$("form").serialize(), u need serialize form

<div id="questionbutton">    <form method="post" name="form_questions" action="">       <textarea name="saveqa"  id="saveqa"></textarea>        <button class="btn_save" id ="btn_save" name="btn_save">ask</button>    </form> </div>       <script src="http://code.jquery.com/jquery-latest.js"></script>         <script>                      $(document).ready(function() {            $('#btn_save').on('click', function() {            $.ajax({             type: "post",             cache: false,              url: "testdata.php",             data:$("form").serialize(),             datatype: "json",             success:function(info){             $('#questiondev').html(info[0]);             console.log(" reponse :"+ info);             }          });         });           $('#btn_save').trigger("click");          });                           </script>  </body> </html> 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -