title: Reverse ajax using DeferredResult of Spring 3.2.0.RELEASE. Not working in IE
body: <p>I am trying to create a demo of Group Chat using reverse ajax in Spring. I am using Spring 3.2.0.RELEASE version.</p>
  
  <p>I am using DeferredResult to perform reverse ajax in my controller. Following is the snippet of my Controller class.</p>
  
  <pre><code>@Autowired
  private AsyncRepository asyncRepository;
  
  Map&lt;Integer, List&lt;DeferredResult&lt;String&gt;&gt;&gt; watchers = new ConcurrentHashMap&lt;Integer, List&lt;DeferredResult&lt;String&gt;&gt;&gt;();
  
  @RequestMapping(value="/asyncRequest/getMessages/{id}", method=RequestMethod.GET)
  @ResponseBody
  public DeferredResult&lt;String&gt; getMessages(final @PathVariable("id") Integer id){
      final DeferredResult&lt;String&gt; deferredResult = new DeferredResult&lt;String&gt;(null, Collections.emptyList());
  
      if(watchers.containsKey(id)) {
          watchers.get(id).add(deferredResult);
      } else {
          watchers.put(id, new ArrayList&lt;DeferredResult&lt;String&gt;&gt;());
          watchers.get(id).add(deferredResult);
      }
  
      deferredResult.onCompletion(new Runnable() {
          @Override
          public void run() {
              watchers.get(id).remove(deferredResult);
          }
      });
  
      return deferredResult;
  }
  
  @RequestMapping(value="/asyncRequest/setMessages/{id}/{message}", method=RequestMethod.GET)
  @ResponseBody
  public String setMessage(@PathVariable("id") Integer id, @PathVariable("message") String message) {
      asyncRepository.setMessage(id, message);
  
      return "";
  }
  
  @Scheduled(fixedRate=1000)
  public void processQueues() {
      for (Map.Entry&lt;Integer, Queue&lt;AsyncDataBean&gt;&gt; entry : asyncRepository.getAsyncBeans().entrySet()) {
          while(entry != null &amp;&amp; entry.getValue() != null &amp;&amp; !entry.getValue().isEmpty()) {
              AsyncDataBean asyncDataBean = entry.getValue().poll();
              for (DeferredResult&lt;String&gt; deferredResult : watchers.get(asyncDataBean.getId())) {
                  deferredResult.setResult(asyncDataBean.getMessage());
              }
          }
      }
  }
  </code></pre>
  
  <p>And below is the Repository class which holds the Map of GroupID and its relevant messageQueue. And it also has the functions for getting and setting the messages for relevant group id.</p>
  
  <pre><code>@Repository
  public class AsyncRepository {
  
      private Map&lt;Integer, Queue&lt;AsyncDataBean&gt;&gt; asyncBeans = new ConcurrentHashMap&lt;Integer, Queue&lt;AsyncDataBean&gt;&gt;();
  
      public String getMessages(Integer id) {
          StringBuilder stringBuilder = new StringBuilder();
          while (asyncBeans.get(id) != null &amp;&amp; !asyncBeans.get(id).isEmpty()) {
              stringBuilder.append(asyncBeans.get(id).poll().getMessage()).append("~");
          }
  
          return stringBuilder.toString();
      }
  
      public void setMessage(Integer id, String message) {
          if(asyncBeans.containsKey(id)) {
              asyncBeans.get(id).add(new AsyncDataBean(id, message));
          } else {
              Queue&lt;AsyncDataBean&gt; messageQueue = new ConcurrentLinkedQueue&lt;AsyncDataBean&gt;();
              messageQueue.add(new AsyncDataBean(id, message));
              asyncBeans.put(id, messageQueue);
          }
      }
  
      public Map&lt;Integer, Queue&lt;AsyncDataBean&gt;&gt; getAsyncBeans() {
          return asyncBeans;
      }
  
      public void setAsyncBeans(Map&lt;Integer, Queue&lt;AsyncDataBean&gt;&gt; asyncBeans) {
          this.asyncBeans = asyncBeans;
      }
  }
  </code></pre>
  
  <p>And below is the data bean I am using to store each message with its group id.</p>
  
  <pre><code>public class AsyncDataBean {
      private Integer id;
      private String message;
  
      public AsyncDataBean() {
      }
  
      public AsyncDataBean(int id, String message) {
          this.setId(id);
          this.setMessage(message);
      }
  
      public Integer getId() {
          return id;
      }
  
      public void setId(Integer id) {
          this.id = id;
      }
  
      public String getMessage() {
          return message;
      }
  
      public void setMessage(String message) {
          this.message = message;
      }
  }
  </code></pre>
  
  <p>And then comes the jsp page for group chat. which looks like below.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      var messagesWaiting = false;
      function getMessages(){
          if(!messagesWaiting){
              $.ajax({ url: "${pageContext.servletContext.contextPath}/asyncRequest/getMessages/${id}", 
                       dataType:"text",
                       success: function(data,textStatus,jqXHR) {
                           if(textStatus == 'success'){
                               messagesWaiting = false;
                               var arr = data.split("~");
                               for(var i=0; i&lt;arr.length; i++)
                               {
                                      try
                                      {
                                          if(arr[i] != '') {
                                              $("#txtaMessages").val($("#txtaMessages").val() + "\n\n" + arr[i]);
                                              document.getElementById("txtaMessages").scrollTop = document.getElementById("txtaMessages").scrollHeight;
                                          }
                                      }
                                      catch(e){
                                       alert(e.message);
                                      }
                               }
                           }
                       }, 
                       complete: function(j) {
                       },
                       error: function(xhr) { 
                       }
              });
              messagesWaiting = true;
          }
      }
      setInterval(getMessages, 1000);
      getMessages();
  
      function sendMessage() {
          var xmlhttp1 = new XMLHttpRequest();
          xmlhttp1.open("GET", '${pageContext.servletContext.contextPath}/asyncRequest/setMessages/${id}/' + $("#txtMessage").val(), true);
          xmlhttp1.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
          xmlhttp1.send();
          $("#txtMessage").val("");
          $("#txtMessage").focus();
      }
  &lt;/script&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
      &lt;h1&gt;Hello World!&lt;/h1&gt;
      &lt;table&gt;
          &lt;tr&gt;
              &lt;td&gt;Messages :: &lt;/td&gt;
              &lt;td&gt;
                  &lt;textarea cols="100" rows="10" id="txtaMessages"&gt;&lt;/textarea&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Send Message :: &lt;/td&gt;
              &lt;td&gt;&lt;input type="text" id="txtMessage"/&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;input type="button" value="Send" onclick="sendMessage();"/&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>That is what I have coded till now to get this working. And everything is working finw in FF and Chrome. But in IE it is not working as expected. The request is never gets hold on the server and it always gets executed every second as configured in the javascript code. And it always returns the same result as previous. I have tried to use several other methods to send ajax request for IE but its not working. Can anyone get it working for me?</p>
  
  <p>Since everything works fine in FF and Chrome, I suspect the problem is with javascript code to send the request to get messages. </p>
  
  <p>Please help me.</p>
  
  <p>Thanks in advance.</p>