I am kind of new to JavaScript library's. I wanted to replace my current code with a JS lib jQuery. My current code looks like this.
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();
}
I wanted to replace my code with something a little friendlier like jQuery's
jQuery.get(url, callback);
However I it doesn't call my callback function.
Also I would like to call this function createRequest to be called continuously. Does jQuery have a nice way of doing that?