1

I am trying to make the following recursive function work but keep receiving an error (following code):

var checkStatus = function(jobID) {
        $.ajax({
            type: 'post',
            url: '/admin/process/check-encode-status.php',
            data: {jobID: jobID},
            success: function(data) {
                if (data == 'processing') {
                checkStatus(jobID).delay(2000);
                } else {
                    $("#videoOutput").html(data);
                }
            }
        });
     };

The error I am receiving is: checkStatus(jobID) is undefined

Everything seems to be working as it should, Firebug is just throwing this warning. The function is repeating itself, posting the jobID and receiving "processing" from the PHP script.

I had a similar script that I was using that used setTimeout() to be recursive but I could not figure out how to pass the jobID along with calling the function (errors).

Any ideas? Thanks!

1 Answer 1

3

Just remove the .delay() and you'll get rid of the error. You should use setTimeout instead.

var checkStatus = function (jobID) {
    $.ajax({
        type: 'post',
        url: '/admin/process/check-encode-status.php',
        data: {
            jobID: jobID
        },
        success: function (data) {
            if (data == 'processing') {
                setTimeout(function() { // <-- send an anonymous function
                    checkStatus(jobID); // <--    that calls checkStatus
                }, 2000);
            } else {
                $("#videoOutput").html(data);
            }
        }
    });
};

This is because checkStatus() doesn't return anything explicitly, so you're trying to call .delay() on undefined.

Sign up to request clarification or add additional context in comments.

1 Comment

Works great, thanks! Kind of dumb of me to use .delay() for that, of course that wouldn't work. Thanks again for the help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.