【jQuery】将form表单通过ajax实现无刷新提交

 1     //将form转换为AJAX提交
 2     function ajaxSubmit(url,frm,fn){
 3         var dataPara=getFormJson(frm);
 4         $.ajax({
 5             url:url,
 6             type:"post",
 7             data:dataPara,
 8             async:false,
 9             dataType:'txt',
10             success:fn
11         });
12     }
13     //将form中的值转换为键值对
14     function getFormJson(frm){
15         var o={};
16         var a=$(frm).serializeArray();
17         $.each(a,function(){
18             if(o[this.name]!==undefined){
19                 if(!o[this.name].push){
20                     o[this.name]=[o[this.name]];
21                 }
22                 o[this.name].push(this.value || '');
23             }else{
24                 o[this.name]=this.value || '';
25             }
26         });
27         return o;
28     }
29 
30 /*
31     //前台调用方式
32     function autoSubmitFun(){
33          ajaxSubmit("autoSumitScoreAJAX.action",$('#formId'),function(){});
34     }
35 */
原文地址:https://www.cnblogs.com/ningvsban/p/3660425.html