weixin_33674976 2016-01-17 12:19 采纳率: 0%
浏览 27

AJAX / PHP的滞后问题原因

So i am trying to make an asynchronous call of a PHP script but for some reason there is an error: Maximum call stack size exceeded that is making my site lagging a LOT. There must be a loop somewhere in my code but i can't really find it. I am looking for the past 3 days and still nothing. If someone could spot anything i would be really greatfull. Thanks in advance!

PHP code:

<?php

    require_once 'li.php'; //File with the constants    

    $Username = $_POST['Username'];

    $query = "SELECT Username
                FROM user_info
                WHERE Username = ?
                LIMIT 1";

    if($stmt = $conn->prepare($query)){   //Prepares the statement!

        $stmt->bind_param('s', $Username); 
        $stmt->execute(); //Executes it!

        if($stmt->fetch()){ //Checks if the query returns anything!

            $stmt->close(); //If yes then closes the prepared statement!
            $error = "Username taken";
            echo $error;
        }   
    }
?> 

AJAX/JS code:

$(document).ready(function(){

    $('#Username').on("keyup", function(){

        $.ajax({
            type: 'POST',
            url: 'NameValidation.php', //Your required php page
            data: { Username: Username }, //pass your required data here
            async: true,
        }).done(function(response){

            if(response != ""){
                $('#UsernameLabel').html("Username Taken!");
            }
        });     
    });
});

In case you didn't understand what i want to do with this code let me explain some more. I want every time the Username input changes to search if the username already exists in the database and alert the user by changing the Label text.

PS: Dont worry about SQL injection security i'll add that later when i fix this problem! ^-^

  • 写回答

1条回答 默认 最新

  • 撒拉嘿哟木头 2016-01-17 12:28
    关注

    you are not closing connection if query returns nothing, try changing the code to :

    if($stmt->fetch()){ //Checks if the query returns anything!
         $error = "Username taken";
         echo $error;
    }  
    $stmt->close(); //close connection in any case
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog