Skip to content

Instantly share code, notes, and snippets.

@egulhan
Created September 18, 2015 09:55
Show Gist options
  • Select an option

  • Save egulhan/11d2edc15a0fe8a4f4eb to your computer and use it in GitHub Desktop.

Select an option

Save egulhan/11d2edc15a0fe8a4f4eb to your computer and use it in GitHub Desktop.
How-to create form on the fly and send via POST method by using JQuery
$(function(){
// create form on the fly
var $new_form = $('<form>', {
'action': '<?php echo BASE_URL; ?>/operation/reset_member_password',
'method': 'POST',
'target': '_top'
}).append(jQuery('<input>', {
'name': 'member_id',
'value': member_id,
'type': 'hidden'
}));
// send form
$new_form.submit();
});
@vukbgit
Copy link
Copy Markdown

vukbgit commented Jul 21, 2021

it seems that you have to append form to the body for submit to work, so last instruction should become:

$new_form.appendTo('body').submit();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment