Results 1 to 4 of 4
  1.    #1  
    I can't figure out how to get my ajax request to work. There's an issue when I try to bind a function to "onSuccess" and "onFailure".

    I can get it to work in the setup() function, but not in the keyupHandler() function.

    Code (error line highlighted):
    Code:
    function MainAssistant(){
            
    }
    
    MainAssistant.prototype.setup = function(){
    
        // Setup text field for the url
        //
        this.controller.setupWidget("url", this.nameAttributes = {
            property: "value",
            limitResize: true,
            textReplacement: false,
            enterSubmits: false
        }, this.nameModel = {
            value: ""
        });
        
        //Setup listeners
        Mojo.Event.listen(this.controller.document, "keyup", this.keyupHandler, true);
        
    };
    
    MainAssistant.prototype.keyupHandler = function(event){
    
        var request = new Ajax.Request("valid url", {
            method: 'get',
            evalJSON: 'false',
            onSuccess: this.receivesuccess.bind(this),
            onFailure: this.receivefailure.bind(this)
        });
        
    }
    
    MainAssistant.prototype.receivesuccess = function(response){
        this.controller.get("status").update('Got Page!');
        
    }
    
    MainAssistant.prototype.receivefailure = function(response){
        this.controller.get("status").update("Error Getting Page");
        
    }
    
    MainAssistant.prototype.activate = function(event){
        /* put in event handlers here that should only be in effect when this scene is active. For
         example, key handlers that are observing the document */
    };
    
    MainAssistant.prototype.deactivate = function(event){
        /* remove any event handlers you added in activate and do any other cleanup that should happen before
         this scene is popped or another scene is pushed on top */
    };
    
    MainAssistant.prototype.cleanup = function(event){
        /* this function should do any cleanup needed before the scene is destroyed as 
         a result of being popped off the scene stack */
    };
    Error:
    Code:
    error: Uncaught TypeError: Cannot call method 'bind' of undefined, app/assistants/main-assistant.jsjsjs:$28$
  2. mosdl's Avatar
    Posts
    781 Posts
    Global Posts
    787 Global Posts
    #2  
    Change:
    Code:
        Mojo.Event.listen(this.controller.document, "keyup", this.keyupHandler, true);
    to
    Code:
        Mojo.Event.listen(this.controller.document, "keyup", this.keyupHandler.bind(this), true);
    Apps: MyQ for Netflix (Phone/TouchPad), Giantbomb (Phone), Excavate (Reddit/Digg clients for TouchPad)
  3. #3  
    Change:

    Code:
    Mojo.Event.listen(this.controller.document, "keyup", this.keyupHandler, true);
    to

    Code:
    this._keyupHandler = this.keyupHandler.bindAsEventListener(this);
    Mojo.Event.listen(this.controller.document, "keyup", this._keyupHandler, true);
    and add:

    Code:
    Mojo.Event.stopListening(this.controller.document, "keyup", this._keyupHandler, true);
    to your cleanup() method.
    Arthur Thornton

    Former webOS DevRel Engineer at Palm, HP, and LG
    Former webOS app developer (built Voice Memos, Sparrow, and several homebrew apps and patches)
    Former blogger for webOS Nation and webOS Roundup
  4.    #4  
    Awesome, thanks guys!

Tags for this Thread

Posting Permissions