js 实现post提交

方法,自己用js构造表单进行提交:

function post(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];        
                // alert(opt.name)        
                temp.appendChild(opt);        
            }        
            document.body.appendChild(temp);        
            temp.submit();        
            return temp;        
} 
post("/tolistUsers",{username:$("#sname").val()});  

 

posted @ 2016-04-05 16:32  phyxis_xu  阅读(474)  评论(0编辑  收藏  举报