jerry looman
jerry looman

Reputation: 13

Uncaught Error: cannot call methods on progressbar prior to initialization; attempted to call method 'value'

I have an problem with my javascript code Which gets an value from an ajax script and should update the progress bar.

<script>
function GetProgress(){
    $.ajax({url: "percentage.php", success: function(result) {
        console.log(result);
        var pers = result;
        $( "#progressbar" ).progressbar("value",pers.value);
        if (pers.value > 0 )
            isDone = true;
        else
            setTimeout(GetProgress(), 2000);
    });
};
GetProgress();
</script>

It doesnt work with update it gets the value right but im getting this error:

Uncaught Error: cannot call methods on progressbar prior to initialization; attempted to call method 'value'

Please help :)

Upvotes: 0

Views: 4591

Answers (2)

jerry looman
jerry looman

Reputation: 13

    <script>
    function GetProgress() {
        $.ajax({
            url: "percentage.php",
            success: function (result) {
                console.log(result);
                var pers = parseInt(result);
                $("#progressbar").progressbar("value", pers);
                if (pers.value > 0) {
                    isDone = true;
                } else {
                    setTimeout(GetProgress, 2000);
                }
            }
        });
    };
    jQuery(function () {
        //initialize the plugin
        $("#progressbar").progressbar();
        setTimeout(GetProgress, 2000);
    })
</script>

Got the solution at last needed to make the value an integer. Thanks for the solution!

Upvotes: 0

Arun P Johny
Arun P Johny

Reputation: 388316

Before calling methods of a plugin, you need to initialize it

function GetProgress() {
    $.ajax({
        url: "percentage.php",
        success: function (result) {
            console.log(result);
            var pers = result;
            $("#progressbar").progressbar("value", pers.value);
            if (pers.value > 0) {
                isDone = true;
            } else {
                setTimeout(GetProgress, 2000);
            }
        }
    });
};
jQuery(function () {
    //initialize the plugin
    $("#progressbar").progressbar();
    GetProgress();
})

Upvotes: 1

Related Questions