I have a Spring MVC controller which returns simply a 0/1 value.
This is my controller
@RequestMapping(value="/{idPiano}")
public String showFloorMap(ModelMap model, @PathVariable int idPiano){
Piano piano = pianoService.findById(idPiano);
String filename = piano.getFileName();
model.addAttribute("idPiano", idPiano);
model.addAttribute("filename", filename);
return "floors/map";
}
@RequestMapping(value="/ajax/{idPiano}", method = RequestMethod.GET)
public @ResponseBody int loadMap(@PathVariable int idPiano){
int result = updateMap.checkMap(idPiano);
return result;
}
map.jsp is the following:
<script type="text/javascript">
function updateMap() {
$.ajax({
url : 'ajax/${idPiano}',
success : function(data) {
if(data===1) {
$('#result').append("<img src=\"/uploads/"+$('#filename').val()+"\" />");
}
}
});
}
</script>
<script type="text/javascript">
var intervalId = 0;
intervalId = setInterval(updateMap, 5000);
</script>
<title></title>
</head>
<body>
<input type="hidden" id="filename" value="${filename }"/>
<div class="row">
<div id="result"></div>
So, every 5 seconds i call the function updateMap, I check if it's 0 or 1, I should append into the div the image. This happens only the first time, but the 0 and 1 are correctly sent to the page.. which is the problem?