In some cases we have a requirement, to POST data i.e.
you’re accessing the URL can’t see the parameters passed, as some information
might be sensitive so we can’t pass POST parameters in URL, but there is an alternative way to post parameters.
Let’s
see the Example –
The below method
is an alternative to Window.open or Window.location.href, if you want to
POST the parameters.
JavaScript Method:-
var
openPost = function (url, params) {
var
formElement = document.createElement("form");
formElement.setAttribute("method",
"post");
formElement.setAttribute("action",
url);
formElement.setAttribute("target",
"_parent");
for
(param in params) {
var
hiddenField = document.createElement("input");
hiddenField.setAttribute("name",
param);
hiddenField.setAttribute("value",
params[param]);
formElement.appendChild(hiddenField);
}
document.body.appendChild(formElement);
formElement.submit();
}
Calling
Method to Redirect -
// CALLING THE
OPENPOST METHOD TO REDIRECT
var
params = [];
params["token"]
= “xyz112121212xysy”;
openPost('/your/redirectURL',
params);
//END OPEN POST METHOD