通過ajax來提交評論,有時候,點擊一次按鈕(type=button),ajax會重復提交多次請求,并且重復的次數也不固定,有時候會多次提交請求,有時候不會,不知道是因為使用button按鈕的原因還是其他的原因?//提交按鈕,是一個的類型$form.find('#commentsubmit').on('click',function(){varcontent=$.trim(um.getContent()),form=this.form,quoteNumber=form.quote_number.value,quoteName=form.quote_name.value,hasComment=$container.find('.replycomment').length>0?1:0;//當前是否存在評論//console.log(content);if(content){varparam={replyId:replyid,content:content,quoteNumber:quoteNumber,quoteName:quoteName,hasComment:hasComment};//這里提交請求,有時候會多次提交$.post('/post/newcomment',param,function(data){if(data.status){if(hasComment){$container.find('.commentlist').append(data.html);}else{$container.prepend(data.html);}$self.attr('data-comments',comments+1).find('.commentsnumber').text(comments+1);}},'json');}});
通過ajax提交表單,點擊按鈕一次,ajax提交多次是什么原因?
牛魔王的故事
2019-04-21 20:41:09