通過ajax來提交評(píng)論,有時(shí)候,點(diǎn)擊一次按鈕(type=button),ajax會(huì)重復(fù)提交多次請(qǐng)求,并且重復(fù)的次數(shù)也不固定,有時(shí)候會(huì)多次提交請(qǐng)求,有時(shí)候不會(huì),不知道是因?yàn)槭褂胋utton按鈕的原因還是其他的原因?//提交按鈕,是一個(gè)的類型$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;//當(dāng)前是否存在評(píng)論//console.log(content);if(content){varparam={replyId:replyid,content:content,quoteNumber:quoteNumber,quoteName:quoteName,hasComment:hasComment};//這里提交請(qǐng)求,有時(shí)候會(huì)多次提交$.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提交表單,點(diǎn)擊按鈕一次,ajax提交多次是什么原因?
牛魔王的故事
2019-04-21 20:41:09