title: How to show model attribute in JSP after using ajax?
body: <p>I have a problem. I pass <code>index</code> value from JSP to controller successfully with ajax. When I click 'pass' button, the 'index' value is increasing and it passes to controller successfully with ajax. According to this index, I add list[index] to model.(with <code>model.addAttribute</code>) Although I have used <code>${nextWord}</code> in the JSP, I cannot see this value in the view. How can I fix it? Thanks for your answer.</p>
  
  <p>Controller</p>
  
  <pre><code>private List&lt;Map&lt;String, Object&gt;&gt; list;
  
  @RequestMapping(value="/practice/{category}", method = RequestMethod.GET)
  public String practicePageStart(@PathVariable("category") String category, 
                                  ModelMap model, HttpSession session){
      // return 10 value from DB. Example;
      // [{idWord=1},{word='exampleWord'},{meaning='turkishMeaning'},{type='NOUN'}]
      list = wordService.getRandomWords(Integer.parseInt(String.valueOf(session.getAttribute("wordCount"))));
      model.addAttribute("wordList", list);
  
      return "practiceCategory";
  }
  
  @RequestMapping(value="/practice/{category}", method = RequestMethod.POST)
  public String practicePagePost(@PathVariable("category") String category, 
              @RequestParam("index") int index, ModelMap model, HttpSession session){
  
      model.addAttribute("nextWord", list.get(index).get("word"));
  
      return "practiceCategory";
  }
  </code></pre>
  
  <p>JSP</p>
  
  <pre><code>&lt;script&gt;
      $(document).ready(function() {                        
          $('#pass').click(function(event) {
              var inputIndex = $('#index').val();
              $.ajax({
                  type: "POST",
                  url: "${pageContext.request.contextPath}/practice/${category}",
                  async: false,
                  data: { index: inputIndex }
                  complete: function(){   
                      alert("${nextWord}");
                      $('#label').text("${nextWord}");
                  }
              });
              document.getElementById("index").value = (parseInt(document.getElementById("index").value) + 1).toString();
          });
      });
  &lt;/script&gt;
  </code></pre>