zoukankan      html  css  js  c++  java
  • 【jQuery】JS中拼接URL发送GET请求的中文、特殊符号的问题

    > 参考的优秀文章

    jQuery ajax - param() 方法

    经常,我们需要在JS中拼接URL然后以GET形式提交请求。如果遇到中文、特殊符号则需要作各种处理。

    jQuery有一个方法非常方便地处理这问题,就是$.param(),此序列化方法$.ajax()也在使用。

    > 简单的例子

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Test $.param()</title>
    </head>
    <script type="text/javascript" src="jquery-1.10.2.js"></script>
    <script type="text/javascript">
    
        function testParam() {
            var param = $.param({
                'text1' : $('#text1').val()
            }, false);
            
            // debug
            alert('param -> ' + param);
            
            window.location.href = "http://localhost:8080/Spring_MVC_demo/jsonCtrl/returnjson?" + param;
        }
        
    </script>
    <body>
    Input String : <input type="text" id="text1" />
    <br/>
    <input type="button" onclick="testParam()" value="submit" />
    </body>
    </html>
    View Code

    测试的输入

    ` 1234567890-=[];',./~!@#$%^&*()_+{}|:"<>?我是中文哦
    View Code

    后台能正常打印。

  • 相关阅读:
    Redis其他知识
    Mybatis的sql语句操作
    Redis
    mybatis插件原理
    mybatis工作原理
    Mybatis逆向工程
    mybatis缓存机制
    Mybatis查询
    zabbix api添加主机
    jenkins + bitbucket 实现 pr自动构建及build状态通知
  • 原文地址:https://www.cnblogs.com/nick-huang/p/5124999.html
Copyright © 2011-2022 走看看