Skip to content

Instantly share code, notes, and snippets.

@canoedf
Created March 17, 2014 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save canoedf/9599070 to your computer and use it in GitHub Desktop.
Save canoedf/9599070 to your computer and use it in GitHub Desktop.
Calling a 2nd page with php/javascript from php/javascript
post_to_url('/grid3/ack.php',{Tm:'%Tm%',Host:'%Host%',Monitor:'%Monitor%',Status:'%Status%',Event:'%Event%'})
<script>
function post_to_url(path, params, method) {
method = method || "post"; // Set method to post by default if not specified.
var form = document.createElement("form");
form.setAttribute("method", method);
form.setAttribute("action", path);
for(var key in params) {
if(params.hasOwnProperty(key)) {
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();
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment