How to reload a div when sending a form?

1

I made a form, which is sent with PHPMailer to an email, after the form is sent returns an alert whether the email has been sent correctly or not. Then I want to reset the form, this I did with the following line of code

$('#formcontacto').trigger("reset");

But this does not reset the google captcha, look how to do this, but I did not find a solution, so if I want to send another email I have to reload the page, but I think it is possible to reload only the div where I have the form, so that in this way after the alert is closed the div is reloaded where I have the form. Is it possible to recharge only the div? If so, how could I do it? I already tried with this

$("#divid").load(" #divid");

But the captcha disappears after the form is submitted.

I also tried with grecaptcha.reset (); But I do not know exactly where I should do this. I put it right after where I reset the form

$(document).ready(function(e) {
$("#formcontacto").validetta({
    onValid:function(e){
        e.preventDefault();
        var x = grecaptcha.getResponse();
        if(x.length == 0){
            $.alert({
                title:"Error Captcha",
                content:"No has marcado el captcha",
                useBootstrap:false,
                boxWidth:"30%"
            });
        }else{
            $.ajax({
                method:"post",
                url:"recaptcha_AX.php",
                cache:false,
                data:{
                    nombre:$("#nombre").val(),
                    empresa:$("#empresa").val(),
                    correo:$("#correo").val(),
                    asunto:$("#asunto").val(),
                    mensaje:$("#mensaje").val(),
                    captcha:grecaptcha.getResponse()
                },
                success:function(resp){
                    $.alert({
                        title:"Gracias por contactarnos!",
                        content:resp,
                        useBootstrap:false,
                        boxWidth:"30%"
                    });
                    $('#formcontacto').trigger("reset");
                    grecaptcha.reset("recaptcha1");
                    //Aquí puse el reset con el id del div en donde tengo el recaptcha
                }
            });
        }
    }
});

});

This code validates that the captcha was marked by sending the form and then sent the form information to a php file where the recaptcha is validated and the form sent to an email. In the last two lines is where I reset the form and where I tried to reset the recaptcha. But it does not work, is this where that reset line has to be? Or where?

    
asked by José Carlos Castillo 10.09.2017 в 20:03
source

1 answer

0

You can try running this line by resetting the form: -

grecaptcha.reset (); // the reset method accepts a parameter, which is the captcha you want to reset

Link enter the description of the link here

    
answered by 10.09.2017 в 22:47