Небольшое отличное решение Tidied Darin.
function myFunction(action, method, input) {
'use strict';
var form;
form = $('<form />', {
action: action,
method: method,
style: 'display: none;'
});
if (typeof input !== 'undefined' && input !== null) {
$.each(input, function (name, value) {
$('<input />', {
type: 'hidden',
name: name,
value: value
}).appendTo(form);
});
}
form.appendTo('body').submit();
}
Это JSLint-совместимый и гарантирует, что форма в конце тега тела не отображается, несмотря на возможные определения CSS.Использование также немного проще, например:
myFunction('/path/to/my/site/', 'post', {
id: 1,
quote: 'Quidquid Latine dictum sit altum videtur'
});