Skip to content

Instantly share code, notes, and snippets.

@otrenav
Last active May 2, 2018 06:57
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 otrenav/24d67a0cdacf59ec1e8cdaf1234d8dff to your computer and use it in GitHub Desktop.
Save otrenav/24d67a0cdacf59ec1e8cdaf1234d8dff to your computer and use it in GitHub Desktop.
Non-AJAX (HTTP) submit using JavaScript
// http://stackoverflow.com/questions/5524045/jquery-non-ajax-post
function submit(action, method, values) {
var form = $('<form/>', {
action: action,
method: method
});
$.each(values, function() {
form.append($('<input/>', {
type: 'hidden',
name: this.name,
value: this.value
}));
});
form.appendTo('body').submit();
}
submit('http://www.example.com', 'POST', [
{ name: 'key1', value: 'value1' },
{ name: 'key2', value: 'value2' },
{ name: 'key3', value: 'value3' },
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment