Quickly submit HTML Form in AJAX

It is best for quickly submit a simple html form via AJAX.

//
//JQuery Part
//
$('#SubmitTheForm').click(function (e) {
    e.preventDefault();
    var $button = $(this);
    var SubmitURL = $('#form').attr("action");
    var FormData = $('#form').serialize();
    $.ajax({
        type: 'POST',
        url: url,
        data: FormData,
        beforeSend: function () {
            $button.attr('disabled', 'disabled');
            $button.html('Working…');
        },
        success: function (result) {         
        },
        error: function (request, status, error) {
        },
        complete: function () {
            $button.removeAttr('disabled');
            $button.html('Submit');
        }
    });
});
//
//C# Part
//
[HttpPost]
public ActionResult AddBr(int id, string name)
{
    return Json("success");
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s