0

Every time when someone types something in the inputfield, I use ajax to check if the username already exists. But this query is very slow. I uploaded the page and it need 2-5s for this query. I use this code here

$('#register_username').bind('input propertychange', function() {
    $.ajax({
        type: "POST",
        url: "check_username.php",
        data: "username="+value
        success: function(response){
           //...
        }
    }
}

In check_username.php is only a sql statement. Im using a free webspace at the moment (lima-city.de). Is that the problem maybe?

You can test it here, enter in the first inputfield Benutzername

3
  • possible duplicate of Check if username exists in database with AJAX Commented Jun 6, 2015 at 21:02
  • We do not know your query and your db structure. So we cannot tell you why it is slow. Maybe an index for your database field should help. But who knows without knowing your db structure. Commented Jun 6, 2015 at 21:07
  • 1
    "But this query is very slow." - so, what does your question have to do with jQuery? How do we know your DB isn't properly indexed? we also don't know how your code is setup for your query. Commented Jun 6, 2015 at 21:19

2 Answers 2

1

Try to do on focusout like below, and check once:-

$(document).bind('focusout','#register_username', function() {
    $.ajax({
        type: "POST",
        url: "check_username.php",
        data: "username="+value
        success: function(response){
           //...
        }
    }
}

Note:- Not only this it will depend on your query code also, that how much efficient it is. that means it will be optimized to give result in minimum amount of time. May be some problem is there also.I am not sure about that

Sign up to request clarification or add additional context in comments.

Comments

1

You can bind the blur event. It will send the query only once you loose focus of the input field.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.