怎样利用JS提交POST请求

来源:互联网 发布:影音风暴mac 编辑:程序博客网 时间:2024/06/08 07:45

一般都是写上隐藏的form标签,用<a href="#" onclick="..."/>来调用js函数然后submit

或者直接在js上自动生成form表单

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('xxx.action', {param1 :param1,param2:'xxxx'});


0 0
原创粉丝点击