[ACCEPTED]-jquery submit form and then show results in an existing div-ajax

Accepted answer
Score: 80

This code should do it. You don't need the 1 Form plugin for something as simple as this:

$('#create').submit(function() { // catch the form's submit event
    $.ajax({ // create an AJAX call...
        data: $(this).serialize(), // get the form data
        type: $(this).attr('method'), // GET or POST
        url: $(this).attr('action'), // the file to call
        success: function(response) { // on success..
            $('#created').html(response); // update the DIV
    return false; // cancel original event to prevent form submitting
Score: 6

This works also for file upload

$(document).on("submit", "form", function(event)

    var url=$(this).attr("action");
        url: url,
        type: 'POST',
        dataType: "JSON",
        data: new FormData(this),
        processData: false,
        contentType: false,
        success: function (data, status)
            $('#created').html(data); //content loads here

        error: function (xhr, desc, err)




Score: 2

You must use AJAX to post the form if you 1 don't want the page to be refreshed.

$('#create').submit(function () {
    $.post('create.php', $('#create').serialize(), function (data, textStatus) {
    return false;

More Related questions