简体   繁体   English

jQuery IE。 ajax请求仅运行一次

[英]Jquery IE. ajax request running only once

This is the code . 这是代码。 Ajax is only running once when i run in the IE. 当我在IE中运行时,Ajax仅运行一次。 But with all other browsers it is running great. 但是与所有其他浏览器一起,它运行得很好。 Untitled Document function cool_add() { //alert(post_id); 无标题的文档功能cool_add(){// alert(post_id); var txt1 = $("#txt1").val(); var txt1 = $(“#txt1”)。val(); $.post('jqueryphp.php', {txt1:txt1}, function(data) { var dat = data; $("div").html(data); }); $ .post('jqueryphp.php',{txt1:txt1},function(data){var dat = data; $(“ div”)。html(data);}); } }

</script>
</head>

<body>

<form>
<input type="text" id="txt1" /><br />
<input type="button" id="butn" onclick="cool_add();">
</form>
<div></div>
</body>
</html>

It is running great in all other browsers but with IE it only runs once thats it. 它在所有其他浏览器中运行都很好,但是使用IE只能运行一次。

IE tends to cache all request and if the request params are same then it will return the cached response. IE倾向于缓存所有请求,如果请求参数相同,则它将返回缓存的响应。 To avoid this, you can use $.ajaxSetup following code which will be applied globally for any future ajax calls. 为了避免这种情况,可以在以下代码中使用$ .ajaxSetup ,该代码将全局应用于以后的任何ajax调用。

$.ajaxSetup ({
      // Disable caching of AJAX responses
      cache: false,
});

You can also apply this cache on a specific call as below, 您还可以按以下方式将此cache应用于特定的调用,

$.ajax ( {
     //..other params
     cache: false,
     //..other params
});

When cache=false , jQuery will add current timestamp to each request so that the request params are unique. cache=false ,jQuery将为每个请求添加当前时间戳,以便请求参数是唯一的。

In your ajax call, make sure to include 在您的ajax通话中,请确保包括

cache: false

IE caches everything, so it assumes your calls are all the same. IE会缓存所有内容,因此假定您的调用都是相同的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM