我想从我的database.php文件中调用特定的函数,并获取返回的值。在这里,我试图做到这一点:
js:
function submit_verification_code(){
$.ajax({
url: "database.php",
type: "post",
data: ({
'code': code_entered,
}),
dataType:"text",
context: this,
success : function(response) {
console.log('RESPONSE: ' + response);
//OPTIONAL_FUNCTION_TO_DO_SOMETHING_WITH_THE_RESPONSE(response);
},
error: function(jqXHR,textStatus,errorThrown){
//OPTIONAL_FUNCTION_TO_DO_SOMETHING_WITH_THE_ERROR(jqXHR);
console.log(errorThrown);
}
});
}
database.php
if(isset($_POST['code'])){
does_code_match($_POST['code']);
}
function does_code_match($code){
connect();
die('test');
$sql = 'select * from emailstobeverified where email=';
$sql .= "'" . $_SESSION['email'] . "'";
$sql .= ' and verification_code=';
$sql .= $code;
$sql .= ';';
$count = query($sql)->num_rows;
die(strval($count));
disconnect();
echo strval($count);
exit;
//Once you've outputted, make sure nothing else happens
}
does_code_match函数执行,并在调用<br />时打印控制台日志console.log("RESPONSE" + response)。但我希望它打印出的价值$count
潇湘沐
阿波罗的战车