好的,此代码适用于除 IE 之外的所有浏览器(同样,这是意料之中的)。代码应该基于 setInterval 进行刷新,并且在除 IE 之外的所有其他浏览器中正常执行,IE 只是不刷新。你能发现问题吗?
var nick = document.getElementById("chatnick").value;
var sessid = document.getElementById("sessid").value;
var room = document.getElementById("roomid").value;
function user_read() {
$.ajax({
type: "GET",
url: "methods.php",
data: {method: "u", room: room},
dataType: "html",
success: function (data, status, xhr) {
$("#userwindow").html(data);
setTimeout(user_read, 10000);
}
});
}
function ajax_read() {
$.ajax({
type: "GET",
url: "methods.php",
data: {method: "r", room: room},
dataType: "html",
success: function (data, status, xhr) {
$("#chatwindow").html(data);
setTimeout(ajax_read, 400);
}
});
}
function submit_msg() {
var msg = document.getElementById("chatmsg").value;
$.ajax({
type: "GET",
url: "methods.php",
data: {method: "w", room: room, m: msg, n: nick, sessid: sessid},
dataType: "html",
success: function (data, status, xhr) {
}
});
document.getElementById("chatmsg").value = "";
}
function keyup(arg1) {
if (arg1 == 13) submit_msg();
}
setTimeout(function(){ajax_read();}, 400);
user_read();
最佳答案
可能是缓存问题,尝试使用 POST 而不是 GET。事实上,如果可以,请在任何地方使用 post,因为 IE 不会缓存 POST 请求/响应。
此外,您清除了在 ajax 函数完成之前发送的消息,这似乎很可疑。尝试像这样重写:
function submit_msg() {
var msg = $("#chatmsg").val();
$.ajax({
type: "POST",
url: "methods.php",
data: {method: "w", room: room, m: msg, n: nick, sessid: sessid},
dataType: "html",
success: function (data, status, xhr) {
$("#chatmsg").val("");
}
});
}
关于javascript - AJAX 的另一个 IE 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3062090/