javascript - ajax post提交后又自動請求了一次get
問題描述
html代碼
<form method='post' class='form-horizontal'> <p class='form-group'><label class='col-lg-2 control-label'>上級權(quán)限</label><p class='col-lg-4'> <select name='pid'><option value='0'>頂級權(quán)限</option>{volist name='authRuleRes' id='authRule'}<option value='{$authRule.id}'><?php if($authRule[’level’]!=0){echo ’|’;} echo str_repeat(’—’, $authRule[’level’]*3)?>{$authRule.title}</option>{/volist} </select></p> </p> <p class='form-group'><label class='col-lg-2 control-label'>權(quán)限名稱</label><p class='col-lg-8'> <input type='text' name='title'/></p> </p> <p class='form-group'><label class='col-lg-2 control-label'>控制器/方法</label><p class='col-lg-8'> <input name='name' type='text' /></p> </p> <p class='form-group'><p class='col-lg-offset-2 col-lg-8'> <input type='submit' value='提交' /> <input type='reset' value='重置'></p> </p></form>
js代碼
$(’.form-horizontal’).submit(function(event) { var data = $(this).serialize(); $.ajax({type:'post',url:'/authrule/add',async:true,data:data,success:function(res){ if(res.code == 1){Notify(res.msg, ’top-right’, ’5000’, ’success’, ’fa-check’, true);return false; }else{Notify(res.msg, ’top-right’, ’5000’, ’danger’, ’fa-times’, true);return false; }} }) return false;})
post提交正常,但是提交后自動請求了一個get,請問哪錯了嗎?
問題解答
回答1:$(’.form-horizontal’) 這個選擇器選擇了一個很大的范圍,事件傳輸就有可能觸發(fā)二次, 建議,寫精確一點(diǎn)比如$(’.form-horizontal input[type=submit]’)
回答2:這個很常見, 跨域了吧?
相關(guān)文章:
1. 怎么在phpstudy中用phpexcel上傳數(shù)據(jù)到MYSQL?2. javascript - 百度搜索網(wǎng)站,如何讓搜索結(jié)果顯示一張圖片加上一段描述,如圖;求教3. phpadmin的數(shù)據(jù)庫,可以設(shè)置自動變化時間的變量嗎?就是不需要接收時間數(shù)據(jù),自動變化4. html5和Flash對抗是什么情況?5. 求救一下,用新版的phpstudy,數(shù)據(jù)庫過段時間會消失是什么情況?6. javascript - win7 npm安裝gulp失敗,已是管理員打開,也設(shè)置了文件權(quán)限7. html - 爬蟲時出現(xiàn)“DNS lookup failed”,打開網(wǎng)頁卻沒問題,這是什么情況?8. boot2docker無法啟動9. mac里的docker如何命令行開啟呢?10. 這是什么情況???
