weixin_33738578 2017-08-23 18:39 采纳率: 0%
浏览 19

PHP Ajax警报将无法正常工作

I am trying to check user is exist from data using PHP and Ajax. Using the following codes:

Ajax

$('#btn_check_pc').click(function() {
  username = $("#username").val();
  $.ajax({
    type: 'POST',
    url: 'process.php',
    data: "username=" + username,
    dataType: 'json',
    beforeSend: function() { //Do Something    
    },
    success: function(response) {
      if (response == 'used') {
        console.log("Username Already In Use");
      }
    }
  });
});

PHP

<?php
    include_once "includes/get_data.php" ;

    $username = $_POST["username"];
    //Validating purchase

    $checkUserRegistered = mysqli_query($db,"SELECT  * FROM  users WHERE username = '$username'") or die(mysqli_error($db));

    if(!mysqli_num_rows($checkUserRegistered)){
        // Do Something
    }else{
         echo 'used';
    }
?>

So When I click the #btn_check_pc button then the PHP code will response used if the username already exists. I want to show it with console.log("Username Already In Use"), but it doesn't show. What I am missing here to show console.log() anyone can help me?

  • 写回答

2条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 有偿找一份verilog语言的cnn代码带讲解
      • ¥15 关于#mysql#的问题:mysql 组内排名,取各组的销售金额前10
      • ¥15 有人用过颜色传感器吗?
      • ¥50 求一个SQL长料切短料的优化排版算法
      • ¥15 python 删除TXT文档中小写字母
      • ¥15 ValueError: not enough values to unpack (expected 2, got 0)
      • ¥15 js怎么禁止修改域名
      • ¥15 Cursor为什么在Windows11打不开
      • ¥30 java调用javacv遇到的问题
      • ¥15 如何使用matlab画出带宽100Khz,时长100ms信号的LFM形式的时频图啊