Last active
May 2, 2018 06:57
-
-
Save otrenav/24d67a0cdacf59ec1e8cdaf1234d8dff to your computer and use it in GitHub Desktop.
Non-AJAX (HTTP) submit using JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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