jQuery ajax在GBK编码下表单提交终极解决方案(非二次编码方法)(3)

来源:未知 责任编辑:责任编辑 发表时间:2014-02-18 03:25 点击:

        s[ s.length ] = encode(key) + '=' + encode(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, "+");
}
上面那段代码并不需要在jquery的源文件重写,可以在你项目的javascript贴上,覆盖它原有的方法,不过必须在jquery加载之后。

经初步验证,上面那段代码在utf-8编码也可以工作正常,大概是编码成unicode的缘故吧。

这样,就不是需要使用什么二次编码,即影响前台,又影响后台。gbk编码下ajax post不再是问题了,此乃是终极解决方法。哈哈。


摘自 Hurry的专栏
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
用户名: 验证码:点击我更换图片
最新评论 更多>>

推荐热点

  • Gb2312转utf-8编码的方法(vbs+js)
  • 如何使用Ajax技术开发Web应用程序(1)
  • js跳转路径问题
  • JavaScript模仿桌面窗口
  • 用js检测两个线段是否相交
  • 运用JavaScript构建你的第一个Metro式应用程序(on Windows
  • 我知道的JavaScript -- 设计模式(桥接)应用之 – 验证器
  • 我是如何去了解jquery的(六),案例之幻灯片轮换
  • Jquery封装幻灯片效果
网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
Copyright © 2008-2015 计算机技术学习交流网. 版权所有

豫ICP备11007008号-1