Pratik M
Pratik M

Reputation: 39

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.

Upvotes: 0

Views: 1239

Answers (3)

Selvakumar Arumugam
Selvakumar Arumugam

Reputation: 79830

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.

Upvotes: 2

manafire
manafire

Reputation: 6084

I suspect this is the caching issue I identified in your question yesterday.

http://www.gtothesquare.com/2010/09/26/if-jquery-ajax-call-not-working-in-internet-explorer-try-this/

Upvotes: 0

naspinski
naspinski

Reputation: 34689

In your ajax call, make sure to include

cache: false

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

Upvotes: 0

Related Questions