• url 传参数时出现中文乱码


    1、前端通过 url 传递参数,但是参数又有中文,在下一个页面接受参数的时候中文会乱码

    解决方案为:  

      定义和用法

    decodeURI() 函数可对 encodeURI() 函数编码过的 URI 进行解码。

    语法

    decodeURI(URIstring);

    具体代码:

    var name = encodeURI(json.cCusAbbName); 
                        var address = encodeURI(json.cCusAddress); 
                        $.alert("信息保存成功", "提示", function() {
                            window.open("/order/detail/addOrder?"+json.cCusCode+"="+name+"="+json.cCusHand+"="+address+"="+json.cCusPhone,"_self");
                        });

    接受的时候:

    var test = window.location.href;
            var str = test.split("?").pop();
            var arrNew = str.split("=");
    console.log(decodeURI(arrNew[1]));

     2、es6 新拼接代码格式

     var html =  '<div class="weui-media-box weui-media-box_appmsg " dataId="'+decodeURI(arrNew[0])+'">
                        <div class="weui-media-box__hd width50">
                            <img class="weui-media-box__thumb" src="../../../images/people_pic.png" alt="">
                        </div>
                        <div class="weui-media-box__bd">
                            <h4 class="weui-media-box__title">'+decodeURI(arrNew[1])+'</h4>
                            <p class="weui-media-box__desc">'+decodeURI(arrNew[2])+'</p>
                        </div>
                        <div class="weui-media-box__bd" onclick="deteleUser(this)" style="max- 14px; 14px;">
                            <p class="weui-media-box__desc"><img src="/images/icon_delete.png" alt=""></p>
                        </div>
                    </div>';
  • 相关阅读:
    Change MYSQL data directory
    Docker distrubution in django
    mongo&node
    理解Docker单机容器网络
    auto dock
    django_restframework_angularjs
    Javascript异步编程的4种方法
    DockerProblem
    Javascript面向对象编程
    scrapy post请求 multipart/form-data
  • 原文地址:https://www.cnblogs.com/haonanZhang/p/7463394.html
Copyright © 2020-2023  润新知