I'm having an issue with Spring MVC and jQuery.
I have a jsp with a 'form' and I needed to do a test where when I click on a button, jquery clears the texts of some "input type = 'Text'".
I even managed to test, but every time I click the button, the 'RequestMapping' method is executed in the class in Java.
So, the class method does a database query and returns on the screen through 'ModelAndView', so if my intention is just to clear the controls on the screen I do not want to be running queries.
Script to clean fields
function limparCampos()
{
$(".cmpTexto").val("");
}
Html Code
<form action="UCC001.htm" method="post">
<table>
<tr>
<td>Nome:</td>
<td><input type="text" class="cmpTexto" value="${cad.nome}" name="nome"/></td>
</tr>
<tr>
<td>Endereço:</td>
<td><input type="text" class="cmpTexto" value="${cad.endereco}" name="endereco"/></td>
</tr>
</table>
<input type="button" onclick="limparCampos()" value="Limpar Campos">
</form>
Class Method
@RequestMapping("/UCC001")
public ModelAndView buscaDados(Cadastro cadastro)
{
Cadastro cad = new Cadastro();
cadastro = retCadastro(); //Retorna dados do banco de dados
ModelAndView mav = new ModelAndView("cadastro");
mav.AddObject("cad", cadastro);
return mav;
}
More or less this is how my code, in short, I want to click on the button, clear the fields without having to execute the method 'searchdata'. When I take the 'Form' tag it works, but I can not return Spring when I click a button.
What can I do to resolve this?