当我点击div时应该刷新div并刷新数据应该显示

时间:2014-12-02 06:45:16

标签: javascript php jquery ajax

$(document).ready(function () {

    var j = jQuery.noConflict();

    j('.refresh').click(refreshDiv);

    j('.refresh').css({

        color: ""

    });

    function refreshDiv() {

        j.ajax({

            url: "refresh.php",

            cache: true,

            success: function (html) {

                j(".refresh").html(html);
            }
        });
    }
});

我有这个代码,但是我很困惑如何显示div得到刷新。请提供一些代码或链接来引用。我正在制作网站,我想在使用ajax刷新div时更新分数。

3 个答案:

答案 0 :(得分:2)

在您的ajax请求中指定dataType:'html',如下所示: -

 j.ajax({
        url: "refresh.php",
        dataType:"html",
        cache: true,
        success: function (html) {
            j(".refresh").html(html);
        }
 });

答案 1 :(得分:0)

您可以使用不同的Ajax状态,请重新Ajax Details Desc

然后把beforeSend()函数放到任何加载gif img

然后在complete()隐藏或删除该图片

成功时将数据返回div。

答案 2 :(得分:0)

尝试将您的函数放在全局范围内并添加相关的数据类型:

 function refreshDiv() {
     $.ajax({
        url: "refresh.php",
        datatype:"html",
        cache: true,
        success: function (html) {
             $(".refresh").html(html);
        }
    });
}

$(document).ready(function () {    
    $('.refresh').click(refreshDiv);
    $('.refresh').css({
        color: ""
    });
});

另一个建议是尝试将$替换为您用于j实用程序的jQuery.noConflict()


A small demo could help you.