Get the Chinese of the URL address without garbled characters

    //window.search取到的是queryString,如:?a=2&b=3
    //将参数存入对象中
    function getRequest() {   
       var url = window.location.search; //获取url中"?"符后的字串   
       var theRequest = new Object();   
       if (url.indexOf("?") != -1) {   
          var str = url.substr(1);   
          strs = str.split("&");   
          for(var i = 0; i < strs.length; i ++) { 
             theRequest[strs[i].split("=")[0]]=decodeURI(strs[i].split("=")[1]); 
             //使用decodeURI(),不能用unescape(),会出现乱码 
          }   
       }   
       return theRequest;   
    }

    //获取单个参数
    function getQueryString(key){
        var reg = new RegExp("(^|&)"+key+"=([^&]*)(&|$)");
        var result = window.location.search.substr(1).match(reg);
        return result?decodeURIComponent(result[2]):null;
    }

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325568293&siteId=291194637