开发者

How to re-enable submit button on ajax sucess?

What is happening that I was getting double entries all the time for people clicking twice on the submit button. So I tried to prevent that by disabling the submit. It works, only I can't enable it again.

I'm trying to disable it when clicked and re-enable again once the ajax function has succeeded, so it can work again and more content can be added. But it's not working, it's staying disabled.

$(document).ready(function(){
    $("form#postbar").submit(function() {
        var addcontbox = jQuery('#addcontbox').attr('value');

        if ( addcontbox.replace(/\s/g,"") == "" ) return false;
        $(':submit', this).attr('disabled', 'disabled');


$.ajax({
type: "POST",
url: "post.php",
data:"addcontentbox="+ addcontentbox,
success: function(){
 $("ul#wall").prepend("<li><a href='newpage.php?wall="+addcontentbox+"' target='_blank'>"+addcontentbox+"</a></li>");
$("ul#wall li:first").fadeIn();
document.postbar_add_post.addcontentbox.value='';
$(':submit', this).attr('enabled', 'enabled');
document.postbar_add_post.addcontentbox.focus();
$('#paging_container').pajinate({
    num_page_links_to_display : 5,
    items_per_page : 10 
});
}
});
return false; 
});
$('#paging_container').pajinate({
    num_page_links_to_display : 5,
    items_per_page : 5  
}开发者_开发知识库);
});
</script>

Any guidance?


You need to remove the disabled="disabled" attribute instead of setting a new attribute enabled="enabled".

Use .removeAttr():

$('form#postbar input[type="submit"]').removeAttr('disabled');
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜