Skip to content Skip to sidebar Skip to footer

Ajax Sending HTTP Request Twice?

I am making A ajax login form great progress so far thanks to A few users on stack flow so far. Now when I check all the fields out if it responds to enter being pressed it is work

Solution 1:

just add preventDefault and return false to the keyup function like that:

$('#field').keyup(function (e) {
    if(e.keyCode == 13) {
        //If enter is pressed vailidate the form
        e.preventDefault();
        $.ajax({
            url: 'ajax/check.php',
            type: 'post',
            data: {
                method: 'fetch'
            },
            success: function (data) {
                $('.chat .messages').html(data);
            }
        });
     return false;
    };       
});

This will prevent the form from submitting when users press ENTER.


Post a Comment for "Ajax Sending HTTP Request Twice?"