How to get return a boolean after a form.submit?

1

I have a customer registration form that runs the submit button on the register button:

document.getElementById("formularioCadastro").submit();

All ok, the registration works, but I wanted to return a BOOLEAN true or false, to see if it was successfully registered or made an error.

I tried the following code:

var sucess = document.getElementById("formularioCadastro").submit();

if(sucess == true){
    alert("cadastrado com sucesso!");
else{
    alert("erro ao cadastrar cliente");
    }
}

But it did not work, can anyone help me?

    
asked by anonymous 06.06.2017 / 20:41

1 answer

1

You can resolve this by using the ajax method of JQUERY .

   $.ajax({

        type: 'POST',
        url : 'ServletName',//aqui você poe o nome do servlet
        async: false,
        data: { param1      :   value1,  //aqui
                param2      :   value2,  //vao
                param3      :   value3,  //os
                param4      :   value4}, //parametros

    success : function(){ //código da função caso sucesso

            alert("Sucesso");

                            },
    error: function(){ //código da função caso de erro

            alert("Falha!"); 

                         }
    );
    
06.06.2017 / 21:09