开发者

Jquery help repeated ajax call

When I submit my form, a repeated ajax call is made it never stop.

Here is my Jquery for the ajax call on form submit:

$('form#formgo').submit(function(e) {
    e.开发者_如何转开发preventDefault();

    $('#comparecontent').empty().html(
        '<p style="text-align:center;">' +
        '<img src="../images/ajax.gif" /></p>');

    var form = $(this).closest('form');

    $.ajax({
        type: form.attr('method'),
        url: form.attr('action'),
        data: form.serialize(),
        success: function(msg){
            $('#comparecontent').html(msg);
        }
    });

    return false;
});


In your ajax call, try specifying a timeout for the request:

$.ajax({
        type: form.attr('method'),
        url: form.attr('action'),
        data: form.serialize(),
        timeout: 3000, // time in milliseconds
        success:function(msg){
$('#comparecontent').html(msg);
    }
});

see the .ajax() documentation for more info on available params http://api.jquery.com/jQuery.ajax/


It seems that something is triggering submit.
Try event.stopPropagation()

$('form#formgo').submit(function(e) {
    e.preventDefault();
    e.stopPropagation();
    ...

Also check if an onchange event is bound to elements with id comparecontent.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜