title: Spring mvc .ajax success with if clause
body: <p>I have a script with should update a div based on the value of a boolean variable i get from a Spring Controller, but i cannot get it to be used.</p>
  
  <p>This is my controller</p>
  
  <pre><code>@RequestMapping(value="/{idPiano}")
      public String showFlooorMap(ModelMap model, @PathVariable int idPiano){
          Piano piano = pianoService.findById(idPiano);
          String filename = piano.getFileName();
          boolean daAggiornare = updateMap.isToUpdate();
          model.addAttribute("idPiano", idPiano);
          model.addAttribute("filename", filename);
          model.addAttribute("daAggiornare", daAggiornare); //this is the variable to check
  
  
          return "floors/map";
      }
  
      @RequestMapping(value="/ajax/{idPiano}", method = RequestMethod.GET)
      public @ResponseBody String loadMap(@PathVariable int idPiano){
          Piano piano = pianoService.findById(idPiano);
          boolean daAggiornare = updateMap.isToUpdate();
          String filename = piano.getFileName();
          String result ="da aggiornare: "+daAggiornare+"&lt;br/&gt;"
                  + "&lt;img src=\"/uploads/"+filename+"\" class=\"center-block\"/&gt;";
  
  
              return result;
      }
  </code></pre>
  
  <p><code>daAggiornare</code> is the variable I pass to the JSP page to check if i need to update or not the div.</p>
  
  <p>In my map.jsp I have this script:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      function updateMap() {
          var aggiorna = ${daAggiornare};
          $.ajax({
              url : 'ajax/${idPiano}',
              success : function(data) {
                  if(aggiorna){
                  $('#result').html(data);
                  } 
              }
          });
      }
  &lt;/script&gt;
  
  &lt;script type="text/javascript"&gt;
  
      var intervalId = 0;
      intervalId = setInterval(updateMap, 5000);
  &lt;/script&gt;
  </code></pre>
  
  <p>I cannot see the image... But if I put off the if condition, my image is shown and refreshed every 5 seconds...</p>