【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 */

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM