title: Long polling with ajax and servlets
body: <p>I'm doing a project using javascript for client side and servlets for server side. I'm trying to implement a way to update client info real time. i.e when a client update some info in the web application, other clients will also see the update. I found that long polling is a good technique for this. This is the code I tried to get to work. </p>
  
  <pre><code>function poll() {
          setTimeout(function() {
          $.ajax({ 
              type: "GET",
              url: "server",
              contentType: "application/json", 
              data: {
                  type: "update",
                  card: "string"
              },
              success: function(data) {
                  alert(data);
              },
              error: function(data) {
                  alert('eroor');
              },
              dataType: "json", 
              complete: poll });
          }, 5000);
  } 
  </code></pre>
  
  <p>I'm trying to send a request to the server every 5 seconds and get the response with new updates. But in all the skeleton codes I saw in the web, <code>data:</code> is not set. Without setting it, how would the sever know the type of request it received since there are other types of requests too. But when I set <code>data:</code> no requests are sent from the client. But without setting <code>data:</code> requests are sent to the server. Is it wrong to set <code>data:</code> ? Without it how would I let the servlet know the type of the request? </p>
  
  <p>I understand that like mentioned in <a href="https://stackoverflow.com/questions/18099798/polling-vs-long-polling">here</a> long polling is not what I'm trying to do. But can anyone explain what I should do and where I'm doing wrong.</p>