Skip to content

Instantly share code, notes, and snippets.

@awesome
Created October 25, 2012 17:42
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save awesome/3954251 to your computer and use it in GitHub Desktop.
Save awesome/3954251 to your computer and use it in GitHub Desktop.
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' },
# ]);
non_ajax_submit = (action, method, values) ->
form = $('<form/>', {
action: action
method: method
})
$.each values, ->
form.append $('<input/>', {
type: 'hidden'
name: this.name
value: this.value
})
form.appendTo('body').submit();
non_ajax_submit 'http://www.example.com', 'POST', [
{name: 'key1', value: 'value1'}
{name: 'key2', value: 'value2'}
{name: 'key3', value: 'value3'}
]
// 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' },
]);
@d8958101
Copy link

d8958101 commented Apr 7, 2022

Thx, this is very userful, simple and straightforward!
By the way, I remove form after submit.

setTimeout(function () {
    $("form").remove();
    alert('success!')
}, 3000);

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