Form submit without jQuery, simple function can be used on fly
Function:
function post_to_url(path, params, method) {
method = method || "post";
var form = document.createElement("form");
form.setAttribute("method", method);
form.setAttribute("action", path);
for(var key in params) {
if(params.hasOwnProperty(key)) {
if(params[key] != null) {
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", key);
hiddenField.setAttribute("value", params[key]);
form.appendChild(hiddenField);
}
}
}
document.body.appendChild(form);
form.submit();
}
Usage:
post_to_url('redirectLocation', {
key1:'value1',
key2:'value2'
}, 'post');
Comments
Post a Comment