How to fix problem with jQuery .post() function in internet explorer?
I have a javascript and jquery code like:
$("#refreshimg").live('click',function(){
$.post('php/newsession.php');
$("#captchaimage").load('php/image_req.php');
return false;
});
It is working everywhere except internet explorer (7,8,9). The image is perfectly reloaded in opera, firefox, chrome but not in explorer.
And my html looks like:
<div id="captchaimage"><img src="captcha/image.php?<?php echo time(); ?>" alt="Captcha image" width="132" height="26" align="left" /></div>
Could be there a problem with .开发者_如何转开发live() or .post() or .load() jQuery function in explorer?
Then I have in my code in the main file:
$("#back_btn").click(function() {
$.post('php/newsession.php');
$("#captchaimage").load('php/image_req.php');
return false;
});
And again, this works everywhere except the internet explorer. Any suggestion?
You are reloading image but you are not waiting for request to be done. So what you can do is
$(document).ready(function(){
$("#refreshimg").live('click',function(){
$.ajax({url: 'php/newsession.php', type: 'post', success: function() { $("#captchaimage").load('php/image_req.php?custom_param='+(new Date()).valueOf()); } });
return false;
});
});
and also add no-cache to your php file
<?
Header('Cache-Control: no-cache');
Header('Pragma: no-cache');
?>
make sure that code above is at the first line, because headers needs to be set first.
and this will work.
精彩评论