views:

124

answers:

1

I have this class method in a mootools class:

getData : function(){
  var r = new Request.JSON({
    url : this.container.getAttribute('data-url'), 
    method : 'post', 
    onSuccess : function(j){
      this.cards = j;
      this.prepareQuiz();
    }.bind(this)
  }).send();
},

In any browser aside from IE this works fine, but in IE I get a this.cards is not defined in a method that occurs after the this.prepareQuiz method does it's stuff. I narrowed the problem to this section by adding an if ($defined(this.cards)) before the this.prepareQuiz call and if I just keep refreshing the page 1 out of every 5 or so times it will work. So the this.cards variable is not being set some of the time for some reason.

Why would this happen?

A: 

My guess would be that due to the asynchronous nature of the call, this.cards is not being initialized by the time it needs to be. At least that's what your symptoms indicate. Try a synchronous call and see if you have the same problem.

edl
Ahh that fixed it. Thanks
trobrock
bad idea, this. change to onComplete and leave async. ajax is not meant to be synchronous and its just asking for trouble...
Dimitar Christoff
@Dimitar - I agree. I simply meant for him to isolate the problem using a synchronous call.
edl