JQuery Ajax提交form工具类
2016-07-23 23:55
344 查看
<script type="text/javascript"> $.fn.serializeObject = function() { var o = {}; var a = this.serializeArray(); $.each(a, function() { if (o[this.name]) { if (!o[this.name].push) { o[this.name] = [ o[this.name] ]; } o[this.name].push(this.value || ''); } else { o[this.name] = this.value || ''; } }); return o; }; $.fn.ajaxForm = function(config){ var form = this; var formJson = $(form).serializeObject(); if(config.data){ $.extend(config.data,formJson); } if(config.beforeSubmit && config.beforeSubmit()===false){ return this; } var options = { success : function(data) { if(config.success){ config.success(data); } if(config.resetForm && config.resetForm===true){ $(form)[0].reset() } if(config.clearForm && config.clearForm===true){ $(form)[0].reset() } }, error : function(data) { if(config.error){ config.error(data); } } } var newConfig = $.extend({},config,options); $.ajax(newConfig); } </script>
相关文章推荐
- python2.0_s12_day13_javascript&Dom&jQuery
- jQuery源码解读一
- jQuery插件记录 <三>使用$.fn添加jQuery对象方法中传递options给定默认值
- jQuery插件记录 <二>使用$.fn添加jQuery对象方法
- (function($){….})(jQuery)
- jQuery.extend 函数详解
- jquery 插件编写例子5个
- 【实践】jquery实现滑动动画及轮播
- jQuery基础-事件篇
- jQuery基础-DOM篇2
- jQuery的validate验证插件使用方法源码
- jQuery $.ajax()通过本地服务器访问到远程服务器,解决远程问题。
- jQuery 怎么实现点击页面其他地方隐藏菜单?
- jquery textarea 启用、禁用 判断状态
- 基于MVC+EasyUI的Web开发框架经验总结(12)--利用Jquery处理数据交互的几种方式
- jquery-zclip插件
- 十条jQuery代码片段助力Web开发效率提升
- bind()、toggle()和hover()的区别
- jquery 操作table tr的例子,以及一个ajax实例。
- 前端 时间个性化 插件 jquery.timeago.js