0°

js 无痕创建表单提交 post 数据

js 无痕创建表单提交 post 数据

// action url路径 ''
// params 参数包 {}
// target 跳转类型 _target
function(action, params, target) {
  var fm = document.createElement("form");
  var params = params || {};
  fm.action = action;
  fm.method = "post";
  fm.target = target || "";
  fm.style.display = "none";
  for (var x in params) {
    var opt = document.createElement("input");
    opt.name = x;
    opt.value = params[x];
    fm.appendChild(opt);
  }
  document.body.appendChild(fm);
  fm.submit();
  document.body.removeChild(fm);
}

本文由【DrChenXX】发布于开源中国,原文链接:https://my.oschina.net/u/3756690/blog/3147088

全部评论: 0

    我有话说: