$(function(){ $('#btn-submit').click(function(event) { var _this = $(this); var pay = $('#payform').find('input[name="pay"]:checked').val() || ''; if(pay == ''){ alert('Please choose an amount.'); return false; } var email = $('#payform').find('input#email').val(); if(email == ''){ alert('Please enter your email!'); return false; } $.ajax({ url:'/todo/payauthor/save', type:'POST', data:$('#payform').serialize(), beforeSend:function(){ //console.log(_this); _this.attr('disabled', true); }, success:function(obj){ if(obj.code == 200){ $('#payinfo').html(obj.message); //$('#payform').remove(); }else if(obj.code == 400){ $('#payinfo').html(obj.message); }else{ alert(obj.message) } }, error: function() { console.log('sorry! something wrong went out!'); } }); return false; }); })