pravi
pravi

Reputation: 444

reload page after ajax jquery

I'm trying to reload a page upon ajax response but its flickering page but its not refreshing or reloading page, Below is my code.

function callAjaxForCount(getCountValue){
    var maxValue = getCountValue;
    var interval = 3000; 
        $.ajax({
        type: "GET",
        url: "/ServletToCheckCondition",
        async: false,
        data: {"totalLoggedMembers": maxValue},
        success: function(data) {
            for (var key in data) {
            var retValue = data[key];       

                if(retValue == 'true')
                {

                  location.reload();
                }
                else if(retValue == 'false')
                {

                }
            }
            },
        error: function() {
            alert("Failed. Try Again.","error");
        },
        complete: function () {
        // Schedule the next
        window.setInterval(callAjaxForCount(maxValue),interval);
         }
        });
    }

This is in a window.open popup window and this function will call when popup starts and keep calling for every 3 seconds repeatedly if the condition satisfies and returns true then page has to reload and it will set new value to page dynamically, But page is not refreshing its flickering continuously.

I used location.reload() , i also tried to keep a hidden button and submitting page but no luck.

Upvotes: 0

Views: 1235

Answers (1)

Perlica
Perlica

Reputation: 62

Try

function callAjaxForCount(getCountValue){
var maxValue = getCountValue;
var interval = 3000; 
    $.ajax({
    type: "GET",
    url: "/ServletToCheckCondition",
    async: false,
    data: {"totalLoggedMembers": maxValue},
    success: function(data) {
        for (var key in data) {
        var retValue = data[key];       

            if(retValue == 'true')
            {

               window.location.reload();
            }
            else if(retValue == 'false')
            {

            }
        }
        },
    error: function() {
        alert("Failed. Try Again.","error");
    },
    complete: function () {
    // Schedule the next
    window.setInterval(callAjaxForCount(maxValue),interval);
     }
    });
}

Upvotes: 1

Related Questions