I created a CometServlet according to this example http://tomcat.apache.org/tomcat-7.0-doc/aio.html. Then I tried to get data from it using JQuery. The code is following:
$(function() {
$.longPoll = function(url, success, error) {
$.ajax({
url : url,
success: function(data, status) {
$.longPoll(url, success, error);
if (success) {
success(data, status);
}
},
error: function(data, status) {
$.longPoll(url, success, error);
if (error) {
error(data, status);
}
}
});
};
$.longPoll("./comet", "", function(data, status) {
alert("success:" + data);
}, function(data, status) {
alert("error:" + data);
});
});
The problem is that the success function doesn't trigger (even though I can see in the FireBug console that the data comes). I think it happens because the server doesn't close a response writer, but it is a goal of the long-polling :)
Does any one have any ideas how it can be solved?
beforeSend : function(xhr) { xhr._onreadystatechange = xhr.onreadystatechange; xhr.onreadystatechange = function() { if (xhr.readyState === 3) { alert(this.responseText); } else { xhr._onreadystatechange(); } }; xhr.onprogress = xhr.onreadystatechange; }
to my $.ajax() request, but nothing changed. Sorry, I can't format the code. – Pavel Aug 31 '10 at 14:29