简体   繁体   中英

Submit form with Ajax and jQuery Modal

How to Submit form with Ajax and jQuery Modal jQuery Modal Site . Here my ajax:

$('#save').submit(function(event) {
    event.preventDefault();
    $.ajax({ 
        data: $(this).serializeArray(), 
        type: $(this).attr('method'), 
        url: $(this).attr('action'), 
        success: function() { 
            $('#message').html("Success").modal();
        }
    });
    return false;
});

You just have to mention the form ID with serialize function and it will work..It doesn't matter that your form is in modal dialog or on page.. Yes but if you are opening form in Iframe than You've to use different method.

use this line with data attribute.

$("#formId").serialize();

$('#save').submit(function(event) {
    event.preventDefault();
    $.ajax({ 
        data: $("#formId").serialize(), 
        type: $(this).attr('method'), 
        url: $(this).attr('action'), 
        success: function() { 
            $('#message').html("Success").modal();
        }
    });
    return false;
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM