使用AJAX刷新和显示jquery

时间:2014-06-30 18:01:46

标签: jquery ajax twitter-bootstrap visual-studio-2013

需要一些关于如何在包含来自AJAX调用的信息的div中刷新和更新信息的指导。目前,在点击更新之前,div被清空。我需要这样做而不将其绑定到click事件处理程序。

以下是代码:

var selectedSize = "Select a Size";
$("#ResidentialBuildingSize").append('<option value="' + selectedSize + '">' + selectedSize + '</option>');
$('option[value="' + selectedSize + '"]').attr('disabled', 'disabled');
$("#ResidentialBuildingStories").change(function () {
    url = '/ResidentialBuilding/getBldgSize?stories=';
    optionElement = $('#ResidentialBuildingStories').val();
    url = url + optionElement;
    $("#ResidentialBuildingSize").empty();
    $("#ResidentialBuildingSize").append('<option value="' + selectedSize + '">' + selectedSize + '</option>');
    $('option[value="' + selectedSize + '"]').attr('disabled', 'disabled');
    $.getJSON(url, function (data) {
        $.each(data, function (index, value) {
            $('#ResidentialBuildingSize').append('<option value"' + value.size + '">' + value.size + '</option>');
        });
    });
    $("#info").click(function () {
        infoHead = "infoHead";
        invisible = "invisible";
        type = $("#ResidentialBuildingType").val();
        stories = $("#ResidentialBuildingStories").val();
        size = $("#ResidentialBuildingSize").val();
        url = "/ResidentialBuilding/getBldgInfo?type=" + type + "&stories=" + stories + "&size=" + size;
        //$("#titles").empty();
        //$("#values").empty();
        $.getJSON(url, function (data) {
            $.each(data, function (index, value) {
                $("#titles").empty();
                $("#values").empty();
                $("#titles").append('<h5 class="' + infoHead + '">' + value.r.type + " (" + value.r.stories + ")" + '</h5>');
                $("#titles").append('<p>' + "Stories" + '</p>');
                $("#titles").append('<p>' + "Age" + '</p>');
                $("#titles").append('<p>' + "Size" + '</p>');
                $("#titles").append('<p>' + "Orientation" + '</p>');
                $("#titles").append('<p>' + "Shape" + '</p>');
                $("#titles").append('<p>' + "Floor Height" + '</p>');
                $("#titles").append('<p>' + "Foundation" + '</p>');
                $("#titles").append('<p>' + "Window Percent" + '</p>');
                $("#titles").append('<p>' + "Heating" + '</p>');
                $("#titles").append('<p>' + "Cooling" + '</p>');
                $("#values").append('<h5 class="' + infoHead + ' ' + invisible + '">' + '&nbsp;' + '</h5>');
                $("#values").append('<p>' + value.r.stories + '</p>');
                $("#values").append('<p>' + value.r.age + '</p>');
            });
        });
    });
});//end change function

1 个答案:

答案 0 :(得分:1)

尝试使用

window.setInterval(function, time)