Created
October 25, 2012 17:42
-
-
Save awesome/3954251 to your computer and use it in GitHub Desktop.
jQuery non-AJAX POST
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
# 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'} | |
] |
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
Thx, this is very userful, simple and straightforward!
By the way, I remove form after submit.