weixin_33743880 2016-10-22 10:55 采纳率: 0%
浏览 18

Ajax总是返回true

function lks()
        {  
            var groupname = document.getElementById('groupname').value;
            $.ajax
            ({ 
                url: 'checkgroupname.php?groupname='+groupname,
                type: 'get',
                success: function(result)
                {
                    alert(result);
                    return false;
                }                    
            });

        }

I have above code for ajax and it goes to always true condition even if I return false; Please help me to sortout this problem

here is checkgroupname.php

<?php
session_start();
$loginuser = $_SESSION['username'];
$groupname = $_GET['groupname'];
$checkgroupname = trim(`sudo grep -w $groupname /home/$loginuser/.groupmanagement`);
if($checkgroupname!=NULL){
    echo json_encode("already");
}
else{
    echo json_encode("allow");
}
?>
  • 写回答

1条回答 默认 最新

  • from.. 2016-10-22 10:58
    关注

    As you said, you use return false to return the value.

    I think, you should use to return data using echo.

    $data = ['returnValue'=> 'true'];
    echo json_encode($data);
    exit(); //exit the execution further
    

    In Ajax success

    console.log(result);
    

    FYI, please make sure that your server side condition / code is working properly.

    评论

报告相同问题?