Mootools calling class method onSuccess Ajax -


i'm trying achieve following:

  1. user clicks on element , cmove function invoked (works)
  2. cmove passes js object ajax method (works)
  3. ajax method submits object move/test controller (php/codeigniter) (works)
  4. controller returns json data (works)
  5. onsucces calls move method stuff (no chance calling method)

so, how can call move method out of onsuccess? , there better way of pushing moveobj around?

var plane = new class({     implements: options,      options: {         action: null     },      initialize: function(options) {         this.setoptions(options);         $('somelement').addevent('click', this.cmove.bind(this));     },       cmove: function(event, action) {          moveobj = new object();         moveobj.x = 123;                      this.ajax('cmove', moveobj);      },     move: function(moveobj) {         console.log("yippe!");  // not getting here :(                   },            ajax: function(action, obj) {          resp = $('resp');          var myrequest = new request.json({             url: '<?php echo site_url('move/test'); ?>',             method: 'get',             onrequest: function(){                 resp.set('text', 'wait...');             },              onsuccess: function(responsetext){                  switch(action)                 {                 case 'cmove':                      test3.move(responsetext); // not working                     this.move(responsetext);  // not working                     parent.move(responsetext);  // not working                      resp.set('text', responsetext.x);                     break;                             },             onfailure: function(){                 resp.set('text', 'sorry, request failed :(');             }         }).send('coords='+ json.encode(obj));                 }  });   window.addevent('domready', function(){     var test3= new plane({}); }); 

you need bind callback function request instance scope of class or save reference of class' instance (self = this) , call via instead:

ajax: function(action, obj) {      var self = this; // save refrence     var resp = document.id("resp");      new request.json({         url: '<?php echo site_url('move/test'); ?>',         method: 'get',         onrequest: function(){             resp.set('text', 'wait...');         },          onsuccess: function(responsetext){              switch(action) {                 case 'cmove':                      self.move(responsetext); // work                     this.move(responsetext);  // work                  break;                           }          }.bind(this), // binding callback instance this.method works         onfailure: function(){             resp.set('text', 'sorry, request failed :(');         }     }).send('coords='+ json.encode(obj));             } 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -