Takes time to complete the response

Hi, can i ask some help i have a form for my registration,when the user type there emails every time they input character(keyup) to the textfield i always send request to the server via ajax to check if it is exist already in the database,but it takes times to responds to the server.when i check in the firebug i can see many request to the server and it is still loading.I think all the response will complete 10 seconds…Is there a way to make it faster to response,?

Thank you in advance.

10 seconds is a very long time! But without any code it’s hard for us to see where the problem might be. Could you show the code, database table(s) involved and an estimation of how many email addresses we’re talking about?

Also, I wouldn’t do an AJAX request for every keyup, but do an AJAX request if the user hasn’t typed anything for say 250ms, that’s how most of these things work.

Basically


var timeout = null;

$('#some-input').on('keyup', function() {
    clearTimeout(timeout);
    timeout = setTimeout(doAjaxRequest, 250);
});

function doAjaxRequest() {
    $.get('/some/path', {email: $('#some-input').val() }, function(response) {
        // do something with the response
    });
}

this prevents the flood of requests you get.

Also, since you’re checking emails, you might go a step further and check that the input at least resembles an email address, i.e., it contains a @ and a . after that @


function doAjaxRequest() {
    var email = $('#some-input').val();
    if (email.indexOf('@') !== -1 && email.lastIndexOf('.') > email.indexOf('@')) { // otherwise it's definitely not a valid email so not worth checking
        $.get('/some/path', {email: email }, function(response) {
            // do something with the response
        });
    }
}

Hi ScallioXTX,

Thank you for this idea,and I will try this and apply to my code…I’ll be back and i will let you know.

Thank you :slight_smile: