2013-01-03 33 views
0

我写了一个ajax调用来更改图像,并在ajax调用成功时在浏览器上显示它。但在IE和Firefox上图像不会改变。它在Chrome上运行良好。如何在ie和firefox中清除ajax缓存?

var url = "/store/artwork/index/renderSVGFile?"+"docID=<?php echo $docID ?>&unique="+(new Date()).getTime(); 
    jQuery('*').css('cursor', 'wait'); 
     jQuery.ajax({ 
      url: url, 
      cache:false, 
      type: "POST", 
      data: {}, 
      success: function(data) { 
       jQuery('#product-img-template').html("<img src='/path/to/image/<?php echo $docID ?+>.png' />"); 
       jQuery('#product-img-template').css("position", "relative"); 
       jQuery('#product-img-template').css("top","-430px"); 
       jQuery('#product-img-template').css("left","-7px"); 
       jQuery('#product-img-template').css("height","400px"); 
       jQuery('#product-img-template').css("margin-bottom","-350px"); 
       jQuery('#product-img-template').css("z-index","20"); 
       jQuery('*').css('cursor', 'auto'); 
      }, 
      failure: function(data) { 
       jQuery('*').css('cursor', 'auto'); 
      } 
     }); 

我可以看到图像已被更改,但未在浏览器上显示。任何人都可以帮助我吗?

回答

1

缓存false与您显示的图像无关。所以对于线

jQuery('#product-img-template').html("<img src='/path/to/image/<?php echo $docID ?+>.png' />"); 

改成这样,例如 - 就像你在一个AJAX网址做

jQuery('#product-img-template').html("<img src='/path/to/image/<?php echo $docID ?+>.png?" + (new Date()).getTime() + "' />"); 
+0

谢谢。有用!!! – CharlesDou