码迷,mamicode.com
首页 > Web开发 > 详细

纯js提交get和post请求

时间:2016-05-26 18:40:14      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:

get

function get(URL, PARAMS)
                        {
                            var temp = document.createElement("form");
                            temp.method = "get";
                            temp.style.display = "none";
                            var data = "?";
                            for (var x in PARAMS)
                            {
                                data += x + "=" + PARAMS[x] + "&";;
                            }
                            data = data.slice(0, data.length-1);
                            temp.action = URL + data;
                            document.body.appendChild(temp);
                            temp.submit();
                            return temp;
                        }

/调用方法 如

get(‘pages/statisticsJsp/excel.action‘, {html :‘prnhtml‘,cm1:‘sdsddsd‘,cm2:‘haha‘});

post

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();
                            document.getElementById("rollback").submit();
                            return temp;
                        }

/调用方法 如
post(‘pages/statisticsJsp/excel.action‘, {html :prnhtml,cm1:‘sdsddsd‘,cm2:‘haha‘});

纯js提交get和post请求

标签:

原文地址:http://www.cnblogs.com/wuxie1989/p/5532157.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!