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
Post a Comment