1
I have a customer registration form that runs Submit on the sign up button:
document.getElementById("formularioCadastro").submit();
everything ok, the registration works, but I wanted to return a BOOLEAN true or false, to know if it was registered successfully or gave 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 didn’t work, someone can help me?
When the form submission happens, it is not directed to the page defined in
action
of the elementform
? Or you’re making an asynchronous request?– Woss
To know if it was successfully registered in fact the answer has to come from the server, only the front is not possible to say that it was "registered" successfully.
– BrTkCa
@Andersoncarloswoss my action calls a Servlet, which registers the customer, and when the method ends I do not know whether it was successful or failed.
– 20comer
@Lucascosta, in my Rvlet I have the second stretch at the end of the method:
request.setAttribute("sucess", "true");
– 20comer
A tip would be to make Submit without updating the screen and call Servlet by ajax, becomes more subtle for the user and make Servlet return an http status: 500 to error or 200 to success. Automatically falls into ajax success or error. Furthermore, it is difficult to play to help you with what @20comer
– BrTkCa
@Lucascosta is just as simple as you see, that’s all. I don’t think I need to use AJAX to accomplish this task, so I just need to get the return of a variable from Let.
– 20comer