weixin_33674437 2016-03-13 22:19 采纳率: 0%
浏览 1

AJAX不会一直更新

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?

  • 写回答

0条回答 默认 最新

    报告相同问题?