Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AJAX的另一个IE问题_Javascript_Jquery_Ajax - Fatal编程技术网

Javascript AJAX的另一个IE问题

Javascript AJAX的另一个IE问题,javascript,jquery,ajax,Javascript,Jquery,Ajax,好的,这段代码适用于除IE之外的所有浏览器(这也是意料之中的)。代码应该基于setInterval进行刷新,并且通常在除IE之外的所有其他浏览器中都会这样做,IE只是不刷新。你能发现问题吗 var nick = document.getElementById("chatnick").value; var sessid = document.getElementById("sessid").value; var room = document.getElementById("roomid").va

好的,这段代码适用于除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("");
    }
});

}

缓存是我在使用AJAX的IE中遇到的一个问题。您是否尝试过在URL中添加一些内容以使其唯一?例如,一个随机整数作为一个参数。

发送不是问题,它正在更新用户读取和ajax读取div。看起来IE正在缓存div,我如何防止它这样做。POST无法解决问题。请在任何地方使用POST,即不缓存POST请求/响应。-为什么不在DOM就绪事件中使用setInterval而不是setTimeout()。在ajax设置中也设置cash:false。因为我对JS和jQuery不熟悉,不知道如何操作DOM。设置cache:false对IE没有任何作用。