title: Use jQuery to replace XMLHttpRequest
body: <p>I am quite new to JavaScript libraries. I wanted to replace my current code with jQuery. My current code looks like this:</p>
  
  <pre><code>var req;
  
  function createRequest() {
     var key = document.getElementById("key");
     var keypressed = document.getElementById("keypressed");
     keypressed.value = key.value;
     var url = "/My_Servlet/response?key=" + escape(key.value);
     if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
     } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
     }
     req.open("Get", url, true);
     req.onreadystatechange = callback;
     req.send(null);
  }
  
  function callback() {
     if (req.readyState == 4) {
        if (req.status == 200) {
           var decimal = document.getElementById('decimal');
           decimal.value = req.responseText;
        }
     }
     clear();
  }
  </code></pre>
  
  <p>I wanted to replace my code with something a little friendlier like jQuery's</p>
  
  <pre><code>$.get(url, callback);
  </code></pre>
  
  <p>However it doesn't call my callback function.</p>
  
  <p>Also I would like to call a function called <code>createRequest</code> continuously. Does jQuery have a nice way of doing that?
  ­­­­­­­­­­­­­­­­­­­­­­­</p>