How to get the Controller VRaptor Result with Jquery?

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><divid="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 want is to just get the contents of mensagemErro set in Controller and inserted in result . Remember that if 2 emails come up, the bank error pops up and the mensagemErro

How to do this?

    
asked by anonymous 08.03.2016 / 21:46

0 answers