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

    后台能正常打印。

  • 相关阅读:
    11.2
    11.1
    10.31JS中级
    10.24
    动画运动
    操作js的样式
    js
    js元素属性
    js轮播
    js计时器
  • 原文地址:https://www.cnblogs.com/nick-huang/p/5124999.html
Copyright © 2011-2022 走看看