开发者

jQuery ajax error when entering "password" into password field

This is a very strange bug and I hope someone has encountered it before.

I'm using jQuery's $.ajax method to post data from a login script. Each time I refresh the lo开发者_如何学Cgin page and enter the word "password" into the password field for the first time, $.ajax's error() method is triggered i.e. ajax fails to communicate with the server. If I then try again without refreshing the page, it manages to communicate with the server without a hitch.

So to summarise, entering the word "password" into a password input field causes $.ajax to fail. I swear I'm not making this up!

var action = $('#myForm').attr('action');
var email = $('#myForm input[name=email]').val();
var password = $('#myForm input[name=password]').val();

$.ajax({    

    url: action,
    type: 'POST',
    data: {
        email: email,
        password: password
    },
    dataType: 'json',
    timeout: 20000,
    cache: false,

    error: function(xhr,status,error){

        alert('Cannot communicate');

    },

    success: function(data){

        alert('OK');

    }

});


Sorry for the waste of time, but I've just found the problem and it wasn't a jQuery bug. I was returning a malformed json object which triggered the error() method. Sometimes you can't see the woods for the trees after coding for 16 hours straight.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜