param: function( a ) {
var s = [ ];
function add( key, value ){
s[ s.length ] = encodeURIComponent(key) + '=' + encodeURIComponent(value);
};
// If an array was passed in, assume that it is an array
// of form elements
if ( jQuery.isArray(a) || a.jquery )
// Serialize the form elements
jQuery.each( a, function(){
add( this.name, this.value );
});
// Otherwise, assume that it's an object of key/value pairs
else
// Serialize the key/values
for ( var j in a )
// If the value is an array then the key names need to be repeated
if ( jQuery.isArray(a[j]) )
jQuery.each( a[j], function(){
add( j, this );
});
else
add( j, jQuery.isFunction(a[j]) ? a[j]() : a[j] );
// Return the resulting serialization
return s.join("&").replace(/%20/g, "+");
} 为什么要替换下呢,为什么要替换成加号呢?return s.join("&").replace(/%20/g, "+");如果用户在输入框中输入了空格的字符串;我用JQuery的序列化方法得到URL串然后提交的方式,就会造成后台数据的不正确,不知道有没有好的办法?
解决方案 »
- struts1.2使用json时报的错误
- 最近IE6是不是有什么更新阿,很多表单都有重复提交的现象
- 请推荐一个不错的JavaScript编辑器,谢谢。
- 屏幕范围内拖动
- 急!如何实现层的定时关闭,请朋友们帮忙
- 关于一个页面放置多个联动下拉菜单的疑问!麻烦大家帮帮忙!进来看看!谢谢!
- javascript如何进行两个时间的比较?
- 我想用JavaScript控制复选框或文本框aa变为灰色不可用:
- 页面A上面有一个链接,点击弹出页面B.B上有一个checkbox选中以后B自动关闭,同时将chekbox的值回传给A的隐含字段
- JS如何获取多个动态添加的表单的数据
- 如何实时计算文本框里的字数
- 如何倒序找最后一个字符的位置?
在json object和json string之间转换
而是因为要把JSON的内容上传到服务器,上传的内容要经过一些编码转换
比如 = & 符号等这些特殊符号是一定要经过转换的,而空格在上传的时候,就要转换成 + 才会被服务器正确识别。而 + 号本身,自然就要转成另一种形式了