In an ASP.NET MVC app I use jQuery for posting data on button-click:
....
$.post(\'<%=
I created a $.form(url[, data[, method = 'POST']])
function which creates a hidden form, populates it with the specified data and attaches it to the . Here are some examples:
$.form('/index')
$.form('/new', { title: 'Hello World', body: 'Foo Bar' })
$.form('/info', { userIds: [1, 2, 3, 4] }, 'GET')
$.form('/profile', { sender: { first: 'John', last: 'Smith', postIds: null },
receiver: { first: 'Foo', last: 'Bar', postIds: [1, 2] } })
With jQuery's .submit()
method you can create and submit a form with a simple expression:
$.form('http://stackoverflow.com/search', { q: '[ajax]' }, 'GET').submit();
Here's the function definition:
jQuery(function($) { $.extend({
form: function(url, data, method) {
if (method == null) method = 'POST';
if (data == null) data = {};
var form = $('