dongshijiao2363 2014-04-29 14:19
浏览 53

ajax(jquery)调用返回false,当特定行存在时应返回true

I've been tinkering on this for a while, any good samaritan may please help without cursing on the silliness of my problem. I would like the following ajax login function to return true if the posted input is present, here is my code php:

                    $cell = $_POST['cell'];
                $link = mysqli_connect("localhost", "user", "pass", "db");

                $query = "SELECT * FROM snoopers WHERE cell='$cell ' LIMIT 1";
                $result = mysqli_query($link, $query)or die(mysqli_error());
                $num_row = mysqli_num_rows($result);
                        $row=mysqli_fetch_array($result);
                        if( $num_row >0 ) {
                            echo 'true';
                        }
                        else{
                            echo 'false';
                        }
                mysqli_close($link);

and below is the front

//Login
$("#login").click(function(e){
    e.preventDefault();
        $.ajax({
            type: "POST",
            url: "http://localhost/sc/new/lib/login.php", 
            datatype:"application/json",
                data: {
                    cell: $("#cell").val()
                    },
                timeout: 6000, 
                success: function(html)
                {
                    $("#result").html(html).show();
                },
                //success: function(html){ if(html=='true') { alert("True"); }else{alert("you are a failure");}},
                beforeSend:function(){
                     //$("body").html("Loading...")
                },
                complete:function(){

                }
            });                                                 
        }); return false;

});
  • 写回答

1条回答 默认 最新

  • dpsu84620 2014-04-29 14:25
    关注

    change

    cell='$cell '
    

    to

    cell='$cell'
    
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP