jquery json ie8和更低版本不更新脚本

时间:2012-02-29 10:36:15

标签: jquery json internet-explorer-8

我遇到的问题是我的json脚本没有在ie8及更低版本上更新。

我猜它是一个缓存问题。我该如何解决这个问题?

这是它正在运行的页面。 http://www.roofracks.co.uk/thule/Roof+Mounted+Bikes+and+Cycles+Racks+and+Carriers/533.php

<script type="text/javascript">

$(document).ready(function() {
    $('#preloader').ajaxStart(function(){
    $(this).show();}).ajaxStop(function(){
    $(this).hide();
});     
    $.post('http://www.roofracks.co.uk/template_load/get_dynamic_prices.php', $("#productPrice").serialize(),
        function(data){
            $('input[id=productID]').val(data.productID);
            $('input[id=productDescription]').val(data.productDescription);
            $('input[id=productPrice]').val(data.productPrice);
            $('.productSinglePrice').html(data.productSinglePrice);
            $('input[id=productThumb]').val(data.productThumb);
            $('input[id=productThumbLarge]').val(data.productThumbLarge);
        },'json');
    $("#productPrice").change(function(){
        $('.productSinglePrice').empty();
        $.post('http://www.roofracks.co.uk/template_load/get_dynamic_prices.php', $("#productPrice").serialize(),
            function(data){
                $('input[id=productID]').val(data.productID);
                $('input[id=productDescription]').val(data.productDescription);
                $('input[id=productPrice]').val(data.productPrice);
                $('.productSinglePrice').html(data.productSinglePrice);
                $('input[id=productThumb]').val(data.productThumb);
                $('input[id=productThumbLarge]').val(data.productThumbLarge);
        },'json');
        return false;

            });                         
});
</script>

2 个答案:

答案 0 :(得分:1)

您可能遇到两种缓存问题。

IE正在缓存脚本本身,因此没有反映出更改。要解决此问题,请在<script>标记中添加包含当前日期/时间的参数,如下所示:

<script src="js/myscript.js?201202291038"></script>

IE正在缓存AJAX请求。要解决此问题,请使用cache功能将false选项设置为$.ajaxSetup(),如下所示:

$.ajaxSetup({cache: false});

答案 1 :(得分:1)

我建议做 Anthony Grist 发布的内容。另外,我认为你的代码可能很多DRYer。我没有测试过这个,但你明白了......

function(data) {

    var ids = ['#productID',
                '#productDescription',
                '#productPrice',
                '#productThumb',
                '#productThumbLarge'];

    for (var i = 0, len = ids.length; i < len; i++) {
        $(ids[i]).val(data[ids[i].match(/[^#]+/)]);
    }

    $('.productSinglePrice').html(data.productSinglePrice);

}
相关问题