0

I've been struggling creating a reload functionality when a getJSON call fails. This is my current code:

        function get_stuff(page) {
        fPage = 'http://mywebsite.com/' + page + '.json';
        $.getJSON(fPage, function (data) {
            // Stuff
        })
        .fail(function () { // Call failed
            get_stuff(page);
        });

This code does reload the function, but a couple of times every millisecond. I thought of adding a delay, however I didn't manage to find a function (I tried delay(ms) and sleep(ms))

I hope anyone is able to help me out

4

1 回答 1

1
setTimeout(function, ms)

例子

setTimeout(function(){
  get_stuff(page)
}, 1000) 

// the function will be executed after 1 second
于 2013-07-25T09:21:02.327 回答