js 中解决路径传参时特殊字符失效的方法

java 解决路径传参时特殊字符失效的方法,将请求改为自定义的post请求,请求参数为对象:

//被调用的方法
function test(value) {
        var params = {"key":value}
        httpPost("路径", params);
    }
    
    //自定义post请求
    function httpPost(URL, PARAMS) {
        var temp = document.createElement("form");
        temp.action = URL;
        temp.method = "post";
        temp.style.display = "none";
        for (var x in PARAMS) {
            var opt = document.createElement("textarea");
            opt.name = x;
            opt.value = PARAMS[x];
            temp.appendChild(opt);
        }
        document.body.appendChild(temp);
        temp.submit();
        return temp;
    }    

 

     

posted @ 2021-06-15 15:50  火娃ღ  阅读(374)  评论(0)    收藏  举报