简体   繁体   中英

MooTools Problem in IE with Request

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM