php - ajax success doesnt alert anything -


i have ajax request , if id succeeds alert data.

if print_r php function correct result.

my ajax:

$.ajax({             type: "get",             url: "getquestions.php",             datatype: "json",             data:{                 compid:  id[4].innerhtml             },             success: function(response){                 alert(response);             }          }); 

my getquestions.php:

<?php include "functions.php";  getquestions($_get['compid']); 

my function getquestions($compid) in functions.php:

function getquestions($compid){     $int=intval($compid);     $vastus=array();     $conn = dbconnect();     $sql="select * bet_question compid = $int";     $result = $conn->query($sql);     if ($result->num_rows > 0) {         while($row = $result->fetch_assoc()) {             array_push($vastus,$row);         }      } else {         echo "error: " . $sql . "<br>" . $conn->error;     }     return  json_encode($vastus); } 

if print_r(getquestions("some valid id")) in getquestion.php valid result , if var_dump($_get['compid']) in getquestion i'll correct id ajax request.

if check if request sent using inspect elements request sent correct params, response empty.

instead of return need use echo , should updated as

if ($result->num_rows > 0) {         while($row = $result->fetch_assoc()) {             array_push($vastus,$row);         }            echo json_encode($vastus);     } else {         echo "error: " . $sql . "<br>" . $conn->error;     }     exit; 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -