dimanche 19 avril 2015

Jquery $.post not working with Spring MVC 4

Jquery $ .post not working on a project using Spring MVC 4 in IntelliJ IDEA.


I need to send the data to the Controller Spring MVC when the checkbox is checked or unchecked! But the parameters are being sent always "null".


What am I doing wrong?





<script src="http://ift.tt/1oMJErh"></script>
<script>
$(document).ready(function () {
$('input[id="chTarefa"]').change(function () {
var id = $(this).attr("idTarefa");
if ($(this).prop('checked')) {
$.post("checkbox.html", {id: id, estado: "marcado"});
alert("Checked");
}
else {
$.post("checkbox.html", {id: id, estado: "desmarcado"});
}
});
});
</script>



Controller:





@Controller
public class CheckboxController {
@RequestMapping("checkbox.html")
public ModelAndView adiciona(String id, String estado) {

ModelAndView mv = new ModelAndView("checkbox");

if(estado.equals("marcado")){
mv.addObject("msg", "Finish!");
}else{
mv.addObject("msg", "No finish!");
}
return mv;
}
}



Html:





<input id="chTarefa" type="checkbox" idTarefa="4" /> Checkbox


Aucun commentaire:

Enregistrer un commentaire