JQuery URL 传参乱码

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/huang_sheng0527/article/details/73468863

编码过程中发现中文通过URL传递会乱码,如下处理后能正常显示

开始传递 

url: 'device_properties.html?name='+encodeURIComponent("春节快乐"),

显示

$('#devicename').html($.getUrlParam('name'));


其中APP.queryParam是我自定义的方法,该方法实现获取url里的参数,代码如下

//  声明抓取URL参数的方法
    (function ($) {
        $.getUrlParam = function (name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return decodeURIComponent(r[2]); return null;
        }
    })(jQuery);


猜你喜欢

转载自blog.csdn.net/huang_sheng0527/article/details/73468863