zoukankan      html  css  js  c++  java
  • js中serialize() 序列化表单时自动url编码

    <!doctype html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>serialise</title>
         <script src="jquery.js" type="text/javascript"></script>
    </head>
    <body>
        <form id="formId" action="">
            <input type="text" name="a" value="安安" />
            <input type="hidden" name="b" value="abc">
    
        </form>
        <script type="text/javascript">
            $(function(){
                var formStr=$('#formId').serialize();
                //序列化中文时之所以乱码是因为.serialize()调用了encodeURLComponent方法将数据编码了
                //原因:.serialize()自动调用了encodeURIComponent方法将数据编码了   
                //解决方法:调用decodeURIComponent(XXX,true);将数据解码    
                params = decodeURIComponent(formStr,true); //关键点
                alert(formStr+'
    '+params);
                $.ajax({
                    'type':'post',
                    'url':'c.php',
                    'data':formStr,
                    success:function(msg){
                        alert(msg);
                    }
                })
            })
        </script>
    </body>
    </html>
    复制代码
    <?php
     $strA=$_POST['a'];
     $strB=$_POST['b'];
     echo $strA."____".$strB;
  • 相关阅读:
    JSONP
    懒加载
    HTTP 状态代码
    java4中创建内对象的方法
    注册jdbc驱动程序的三种方式
    java Clone()克隆
    Class.forName()的理解
    Bitmap介绍
    前端-PC端瀑布流【10张图】
    百度小程序-图片画廊-使用previewImage方法实现
  • 原文地址:https://www.cnblogs.com/CodingAndRiding/p/8129888.html
Copyright © 2011-2022 走看看