Ajax code to submit given details

$('.contact-form').on('submit',function(e){
    e.preventDefault();
    if($('.contact-form').valid()) {

        var firstname = $('#firstname').val();
        var emailid = $('#email').val();
        var enquiry = $('#message').val();
        console.log(firstname);
        console.log(emailid);
        var datas = {
            email:emailid,
            firstname: firstname,
            message: enquiry
        };
        $.ajax({
            url: url.build('quote/Mainquote/ContactPost'),
            showLoader: true,
            type: 'POST',
            data: datas,
            success: function (res) {
                if (res.status == 200) {
                    swal.fire({
                        title: "Submitted",
                        text: res.message,
                        icon: "success",
                        timer: 2000,
                        showConfirmButton: true,
                        confirmButtonColor: '#9FC33A',
                    }).then(window.location.reload());
                }
                else{
                    swal.fire({
                        title: "Error",
                        text: res.message,
                        icon: "error",
                        timer: 2000,
                        showConfirmButton: true,
                        confirmButtonColor: '#9FC33A',
                    })

                }
            }
        })
    }
    else{
        $('.mage-error:nth-of-type(2)').remove();
        swal.fire({
            title: "Please Enter the Details",
            icon: "error",
            button: "Retry",
            confirmButtonColor: '#D61B0C',
        })
    }
});

Leave a comment

Your email address will not be published. Required fields are marked *