0
I have a controller.
Newslettercontroller.java
@Controller
public class NewsletterController{
@Inject
private Result result;
@Post("/gravarEmail")
public void gravarEmail(String email){
String mensagemErro = "";
CadastroEmail cadEmail = new CadastroEmail();
cadEmail.setEmail(email);
try{
cadEmail.gravar();
}catch(Exception e){
e.printStackTrace();
mensagemErro = "Não foi possivel gravar o email";
}
result.include("mensagemErro",mensagemErro);
}
}
And I have the code
$('#btnEnviar').click(function() {
var email = $('email').val();
$.post("/gravarEmail", {
email: email
}, function(status) {
//Aqui é onde quero pegar o atributo do Controller o mensagemErro;
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<div id="divEmail">
Insira o email:
<br/>
<input type="text" name="email" id="email" />
</div>
<div id="divBtnGravar">
<input type="button" name="Enviar" id="btnEnviar" value="Enviar" />
</div>
What I intend to do is just take the contents of mensagemErro
set in Controller and inserted in result
. Remembering that if you see 2 similar emails, you will have an error in the bank mensagemErro
How to do this?
tried to give a console.log(status) to see the object it returns?
– Emir Marques
@Emirmarques , the
console.log(status)
returns 'Success', added date in Function thusfunction(data,status)
and thedata
returns empty, but nothing I can catch themensagemErro
which is completed in the Controller– Tiago Ferezin
Try the following result.use(json()). from(messageErro). serialize();
– Emir Marques