views:

18

answers:

1

I am having trouble passing the url of $.PhotoUpdater.doUpdate(url) to do the doUpdate function.

Firefox returns this error :

useless setTimeout call (missing quotes around argument?)
[Break on this error] timer = setTimeout($.PhotoUpdater.doUpdate(url), 5000) 

my code:

$.extend({
  PhotoUpdater: {

    startUpdate: function(organization, gallery){
      url = "/organizations/" + organization + "/media/galleries/" + gallery + "/edit_photo_captions"
      timer = setTimeout($.PhotoUpdater.doUpdate(url), 5000)
    },
    stopUpdate: function(){
      clearTimeout(timer);
      timer = 0;
    },
    doUpdate: function(url){
      $.ajax({type: "GET", url: url, dataType: "script"});
    }
  }
});

How I call it:

$.PhotoUpdater.startUpdate("#{@organization.id}", "#{@gallery.id}");
+3  A: 

You need to pass a function into window.setTimeout, not the result of calling a function:

startUpdate: function(organization, gallery){
    url = "/organizations/" + organization + "/media/galleries/" + gallery + "/edit_photo_captions";
    timer = window.setTimeout(function() {
        $.PhotoUpdater.doUpdate(url)
    }, 5000);
},
Tim Down
Thanks so much Tim Down
Trip