-2

我想每 10 秒请求一次此 AJAX 响应以获取结果

function show() {
    var ele = document.getElementById("ping");
    if (ele.style.display == "none") {
        ele.style.display = "block";
    }
    jQuery.ajax({
        type: "POST",
        url: "checkit.php",
        cache: false,
        success: function (response) {
            if (response == 1) {
                alert("Success");
            }
        }
    });
}
4

1 回答 1

-1

你需要一个定时循环。

function show() {
    var ele = document.getElementById("ping");
    if (ele.style.display == "none") {
        ele.style.display = "block";
    }

    window.setInterval(function(){ //loop

        jQuery.ajax({
            type: "POST",
            url: "checkit.php",
            cache: false,
            success: function (response) {
                if (response == 1) {
                    alert("Success");
                }
            }
        });

    }, 10000); //10000 = 10 seconds

}
于 2013-01-21T14:31:02.737 回答