chihung
10/30/2019 - 8:43 AM

add alert when form is send complete

    jQuery(".container-form").submit(function(e) {

        e.preventDefault(); // avoid to execute the actual submit of the form.

        var form = jQuery(this);
        var url = form.attr('action');

        jQuery.ajax({
            type: "POST",
            url: url,
            data: form.serialize(), // serializes the form's elements.
            success: function(data)
            {
                //alert("送信しました"); // show response from the php script.
                alert('送信しました') ? "" : location.reload(); // for reload page
            }
        });


    });
    
    //jQuery can be $
    jQuery(document).ready(function ($) {
        $('.container-form').validate({
            errorPlacement: function (error, element) {
                var $container = element.parents('p').find('.error-container');

                if (element.attr("name") === "個人情報の取扱いについて") {
                    error.appendTo($container);
                } else {
                    error.insertAfter(element);
                }
            },

            submitHandler: function(form) {
                // do other things for a valid form
                form.submit();
                if(alert('送信しました')){}
                else    window.location.reload();
            }

        });
    });