简体   繁体   中英

Jquery IE. ajax request running only once

This is the code . Ajax is only running once when i run in the IE. But with all other browsers it is running great. Untitled Document function cool_add() { //alert(post_id); var txt1 = $("#txt1").val(); $.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 tends to cache all request and if the request params are same then it will return the cached response. To avoid this, you can use $.ajaxSetup following code which will be applied globally for any future ajax calls.

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

You can also apply this cache on a specific call as below,

$.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.

In your ajax call, make sure to include

cache: false

IE caches everything, so it assumes your calls are all the same.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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