jquery从1.3.2升级到1.11.1后,$.ajax提交数组的设置
2014-05-24 15:53
204 查看
在对一个老的项目添加新功能,需要用到jquery1.11,以前用的都是jquery1.3.2。升级到1.11.1以后,发现通过$.post提交数组,参数名称会自动加一个[],搜百度,找到一些方案,单都不是很好,需要改动原来的代码,无奈大致看了下 jquery1.11.1部分的代码。找到ajax相关的代码。
1 先在页面导入jquery
2 在script 标签中写
// Serialize an array of form elements or a set of // key/values into a query string jQuery.param = function( a, traditional ) { var prefix, s = [], add = function( key, value ) { // If value is a function, invoke it and return its value value = jQuery.isFunction( value ) ? value() : ( value == null ? "" : value ); s[ s.length ] = encodeURIComponent( key ) + "=" + encodeURIComponent( value ); }; // Set traditional to true for jQuery <= 1.3.2 behavior. if ( traditional === undefined ) { traditional = jQuery.ajaxSettings && jQuery.ajaxSettings.traditional; } // If an array was passed in, assume that it is an array of form elements. if ( jQuery.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) { // Serialize the form elements jQuery.each( a, function() { add( this.name, this.value ); }); } else { // If traditional, encode the "old" way (the way 1.3.2 or older // did it), otherwise encode params recursively. for ( prefix in a ) { buildParams( prefix, a[ prefix ], traditional, add ); } } // Return the resulting serialization return s.join( "&" ).replace( r20, "+" ); };最好的解决方案是:
1 先在页面导入jquery
2 在script 标签中写
jQuery.ajaxSettings.traditional = true;然后 $.post提交数组就正常了。
相关文章推荐
- jquery中ajax提交数组参数
- jQuery的ajax()方法提交数组问题
- jQuery的ajax 方法提交多个对象数组问题 C# traditional $.param
- jQuery的ajax()方法提交数组问题
- 用ajax,将表单提交到后端,后端php向前端返回数组,前端通过jquery遍历
- jQuery的ajax()方法提交数组问题
- jQuery的ajax()、post()方法提交数组,参数[] 问题
- jQuery的ajax 方法提交多个数组问题
- jquery.ajax提交多值(数组)
- jQuery 防止Ajax重复提交的简单设置方法
- 当 ASP.NET MVC 邂逅 JQuery.Ajax 提交数组
- Dwz/Jquery--使用Ajax提交表单时调用表单设置的校验
- 使用Jquery实现可编辑的表格 并使用AJAX提交到服务器修改数据
- [转]结合PHP实例谈谈如何解决jQuery.ajax提交GB2312或GBK编码中文乱码问题
- 利用jQuery Form插件实现表单的ajax提交(原创)
- .NET ScriptManager PageMethod的应用 一次提交多行数据 (感觉像jquery 的$.ajax)
- JQuery Form Ajax提交Asp.Net表单时的验证视图状态 MAC 失败
- 按钮只能一次提交:ajax页面中调用ascx控件,如何设置ascx中按钮为false
- jQuery 学习笔记四 Ajax提交数据
- jQuery--Ajax提交页面数据