JQuery插件应用(二)

今天说说jQuery.Form,jQuery.Form的官方网站是http://jquery.malsup.com/form/
提到jQuery.Form首先得说说Ajax数据传递乱码问题,Ajax数据传递编码为UTF-8,无论你设置了程序级编码还是页面级编码,Jquery都会使用UTF-8的编码方式传递过去,如果你采用GBK,GB2312方式会。简单起见需要从JQuery源码着手。

[color=blue][b]1、jQuery 1.2.6 乱码解决办法[/b][/color]
论坛里可以找到http://www.iteye.com/topic/339793,具体如下:

param: function( a ) {
var s = [];

// If an array was passed in, assume that it is an array
// of form elements
if ( a.constructor == Array || a.jquery )
// Serialize the form elements
jQuery.each( a, function(){
s.push( encodeURIComponent(this.name) + "=" + encodeURIComponent(encodeURIComponent( 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 ( a[j] && a[j].constructor == Array )
jQuery.each( a[j], function(){
s.push( encodeURIComponent(j) + "=" + encodeURIComponent(encodeURIComponent( this )) );
});
else
s.push( encodeURIComponent(j) + "=" + encodeURIComponent(encodeURIComponent( jQuery.isFunction(a[j]) ? a[j]() : a[j] )) );

// Return the resulting serialization
return s.join("&").replace(/%20/g, "+");
}

[color=blue][b]2、jQuery 1.3.2 乱码解决办法[/b][/color]

param: function( a ) {
var s = [ ];

function add( key, value ){
s[ s.length ] = encodeURIComponent(key) + '=' + encodeURIComponent(encodeURIComponent(value));
};

修改完后再程序里,比如struts的action里用java.net.URLDecoder.decode(param, "UTF-8");进行转码。

书归正传,上一段jquery.form代码:

<s:form id="searchForm" theme="simple" action="monitorItemListView" namespace="/monitorinfo">
名称:<s:textfield name="monItemsName" />
<s:submit value="提交" /></label>
</s:form>


$(document).ready(function() {
var options = {
success : function(msg){
//alert(msg);
$("#item_list").html(msg);
}, // post-submit callback
type : "post", // 'get' or 'post', override for form's 'method' attribute
resetForm: true
//timeout: 3000
};

// bind form using 'ajaxForm'
$('#searchForm').ajaxForm(options);
});

代码非常简单,一看就明白了,有啥米问题可以留言讨论。最后奉上修改后的支持GBK的jquery和Jquery混淆工具。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值