Create a gist now

Instantly share code, notes, and snippets.

function to redirect a webpage to another using post method
function redirect_by_post(purl, pparameters, in_new_tab) {
pparameters = (typeof pparameters == 'undefined') ? {}: pparameters;
in_new_tab = (typeof in_new_tab == 'undefined') ? true: in_new_tab;
var form = document.createElement("form");
$(form).attr("id", "reg-form").attr("name", "reg-form").attr("action", purl).attr("method", "post").attr("enctype", "multipart/form-data");
if (in_new_tab) {
$(form).attr("target", "_blank");
}
$.each(pparameters,
function(key) {
$(form).append('<input type="text" name="' + key + '" value="' + this + '" />');
});
document.body.appendChild(form);
form.submit();
document.body.removeChild(form);
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment