How to get true or false from PHP function using AJAX?

后端 未结 6 1301
傲寒
傲寒 2021-01-23 14:31

I tested status.php return value with var_dump($result) and alerted it out in check() function like this:

function check() {
    $.ajax({
               


        
6条回答
  •  耶瑟儿~
    2021-01-23 14:52

    You cannot get the response by return method in ajax. to get value "echo" whatever the result in the function , like

    function status(){
        if(logged() === true) {
            $result = "1";
        } else {
            $result = "0";
        }
        echo $result;exit;
    }
    

    you will get the value 1 or 0 in your ajax success function

提交回复
热议问题