我有一个AJAX请求,如果获得id成功,我想提醒数据。ajax成功不会提醒任何
如果我print_r
我的PHP函数我得到正确的结果。
我的ajax:
$.ajax({
type: "GET",
url: "getQuestions.php",
datatype: "json",
data:{
compid: id[4].innerHTML
},
success: function(response){
alert(response);
}
});
我getQuestions.php:
<?php
include "functions.php";
getQuestions($_GET['compid']);
我的功能getQuestions($ compid)中的functions.php:
function getQuestions($compid){
$int=intval($compid);
$vastus=array();
$conn = dbconnect();
$sql="SELECT * FROM bet_question WHERE 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);
}
如果我这样做print_r(getQuestions("some valid id"))
在getQuestion.php
我得到有效的结果,如果我做var_dump($_GET['compid'])
in getQuestion
I'l我从ajax请求中获得正确的ID。
如果我检查请求是否使用检查元素发送,我得到的请求发送正确的参数,但响应是空的。
尝试检查此json_encode($ vastus);是否有任何价值 –
使用'ajax'的'error'回调和控制台错误对象 – Tushar
您必须使用一些输出函数,如echo或exit来打印结果 – Cr3aHal0