阶段1:我正在使用JSP和Servlet编写一个用Java编写的Chat程序。 Servlet和附带的类位于服务器端,而JSP页面则处理客户端用户界面。最初我使用FireFox浏览器来显示JSP页面并使用JQuery代码,直到一切正常。
阶段2:所以现在我正在使用IE 11测试整个事情。我不需要告诉我现在有多沮丧,其中一个功能没有按预期工作。该函数名为getMessages(),如下所示:
var roomID = 0; //DEFAULT
var NORMAL_MESSAGE_CODE = "1";
var LOGIN_MESSAGE_CODE = "2";
var LOGOUT_MESSAGE_CODE = "3";
var LOGIN_MESSAGE = "has joined us";
var LOGOUT_MESSAGE = "has left us";
var last=-1;
//Create a flag to determine that the user is logged in or not.
var loggedIn = false;
var MessageTimer;
$.fn.getMessages = function(){
//Call the server and get all the messages up to this point.
console.log("getMessages");
var list;
$.ajax({
type: "GET",
url: "/ChatEngine/ChatServlet/messages/get?roomId=" + roomID + "&sinceId=" + last,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
console.log("getMessages - msg.code: " + msg.code + " msg.message: " + msg.message);
if (msg.code == NORMAL_MESSAGE_CODE)
{
console.log("getMessages - calling updateMessageBoard with normal message");
$(document).updateMessageBoard(msg);
}
else if(msg.code == LOGIN_MESSAGE_CODE || msg.code == LOGOUT_MESSAGE_CODE)
{
//Someone has either joined the chat or has left the chat.
//Therefore, update the list of users in chat.
console.log("getMessages - calling updateMessageBoard with login/logout message");
$(document).updateMessageBoard(msg);
if(msg.code == LOGOUT_MESSAGE_CODE)
{
setTimeout(function(){
$(document).getUserList($(document).updateUserList);
},3500);
}
else
{
$(document).getUserList($(document).updateUserList);
}
}
if(loggedIn)
{
MessageTimer = setTimeout($(document).getMessages,3000);
}
else
{
MessageTimer = clearTimeout(MessageTimer, 500);
}
},
error: function(err) {
alert('Get Messages Error:' + err.responseText + ' Status: ' + err.status);
}
});
};
$.fn.processSuccessfulLogin = function(result){
if (result.code == NORMAL_MESSAGE_CODE || result.code == LOGIN_MESSAGE_CODE || result.code == LOGOUT_MESSAGE_CODE)
{
//Get the list of users currently logged in
$(document).getUserList($(document).updateUserList);
setTimeout(function(){
loggedIn = true;
$(document).sendMessage(LOGIN_MESSAGE);
setTimeout($(document).getMessages,1000);
}, 2000);
}
else
{
alert("Unable to login. code: " + result.code + " message: " + result.message + " username: " + result.username);
}
};
函数processSuccessfulLogin()最初调用getMessages()。如果工作正常,getMessages()会在每3秒后继续调用自身(它在FireFox中执行但在IE中不执行)。
我在IE中看到了几个奇怪的行为。
这是界面的图片:
我希望其中一些人能够与一些jquery老兵敲响钟声,他们必须让他们的代码与两种浏览器兼容,并且从经验中知道需要做些什么改变才能使这件事工作。请指教。
艾伦