我想從我的database.php文件中調(diào)用特定的函數(shù),并獲取返回的值。在這里,我試圖做到這一點(diǎn):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函數(shù)執(zhí)行,并在調(diào)用<br />時(shí)打印控制臺(tái)日志console.log("RESPONSE" + response)。但我希望它打印出的價(jià)值$count
如何使用AJAX調(diào)用PHP函數(shù)并獲取返回值?
慕工程0101907
2021-05-07 14:21:27