Design & Download
Your JS Library
in Seconds!!!

Snippet: Post URL Parameters

Written by Christopher West (cwest) on November 29, 2015.
function postURL(url, opt_multipart) {
  var form = document.createElement("FORM");
  form.method = "POST";
  if(opt_multipart) {
    form.enctype = "multipart/form-data";
  }
  form.style.display = "none";
  document.body.appendChild(form);
  form.action = url.replace(/\?(.*)/, function(_, urlArgs) {
    urlArgs.replace(/\+/g, " ").replace(/([^&=]+)=([^&=]*)/g, function(input, key, value) {
      input = document.createElement("INPUT");
      input.type = "hidden";
      input.name = decodeURIComponent(key);
      input.value = decodeURIComponent(value);
      form.appendChild(input);
    });
    return "";
  });
  form.submit();
}

postURL() API Documentation

Description

Takes a URL and goes to it using the POST method.

Parameters

  1. url {string}:
    The URL with the GET parameters to go to.
  2. opt_multipart {Boolean=}:
    Optional. Defaults to false. Indicates that the data will be sent using the multipart enctype.