Results 1 to 7 of 7
  1.    #1  
    I've just created a new project through Komodo to try and mess around with AJAX a bit to aid another app I'm working on. However I keep getting this error whenever I run the program:

    error: Uncaught TypeError: Cannot read property 'apply' of undefined


    There's nothing actually in the application other than one scene with a simple div with an id to put the responsetext in it. The AJAX request runs in the activate method.

    I've searched around a bit and can only find one reference to it in some IRC logs with no proposed solution. Anyone else encountered this or have any clues as to what the problem might be?
  2. #2  
    code?
    danNielson.com - Slalom - twitter - facebook
    A posted thanks dies with the thread. Clicking the button lasts until the admins get bored with this site and throw it in the recycling bin.
  3.    #3  
    Here it is. I've changed it so that a button event fires it instead (just incase requests are not possible via activate method).

    Main-Assistant.jsjsjs

    Code:
    function MainAssistant() {
    }
    
    MainAssistant.prototype.setup = function() {
        this.controller.setupWidget(
            'buttonTest',
            { label: 'Test'},
            {}
        );
        this.controller.listen(
            this.controller.get('buttonTest'),
            Mojo.Event.tap,
            this.buttonTap.bind(this)
        )
    };
    
    MainAssistant.prototype.activate = function(event) {
    };
    
    MainAssistant.prototype.deactivate = function(event) {
    };
    
    MainAssistant.prototype.cleanup = function(event) {
    };
    
    // -------------------------------------------------------------------------- //
    
    MainAssistant.prototype.handle = function(item) {
        Mojo.Log.info('SUCCESS');
        this.controller.get('content').innerHTML = item;
    };
    
    MainAssistant.prototype.fail = function(item) {
        Mojo.Log.info('FAIL');
        Mojo.Log.info(item);
    };
    
    MainAssistant.prototype.buttonTap = function(event) {
        Ajax.Request(
            'file.txt',
            {
                method: 'get',
                onSuccess: this.handle.bind(this),
                onFailure: this.fail.bind(this)
            }
        );
    };
  4.    #4  
    Ok, I've tried using standard XMLHttpRequest object to perform a request and it works, but the handler event fires 5 times...

    I'm a little confused and I can't find any decent documentation regarding dos and donts when it comes to AJAX on WebOS. Starting to feel frustrated.

    UPDATE: Ok, my bad, I forgot to check the readyState so of course the method fired once for every state change. However, I still cannot work out why Ajax.Request is returning the error that I mentioned in the first post.
    Last edited by semprance; 09/03/2010 at 06:40 PM.
  5. #5  
    Ajax works with JSON file instead of txt file.
    A json file is text file with a dedicated format.

    Here is an exemple:
    Main-Assistant.jsjsjs
    Code:
    MainAssistant.prototype.buttonTap = function(event) {
    var url = Mojo.appPath + 'Database/My_File.json';
    	var request = new Ajax.Request(url, {
    	method: 'get',
    	evalJSON: 'force',
    	onSuccess: this.gotResults.bind(this),
    	onFailure: this.failure.bind(this)
    	});
    };
    
    MainAssistant.prototype.gotResults = function(transport) {
    	var r = transport.responseJSON;
    	this.Item = r.Item;
       	this.controller.get('Item').innerHTML = this.Item;
    }
    
    MainAssistant.prototype.failure = function(transport){
    Mojo.Controller.getAppController().showBanner($L("Item: ") + this.Item, "","Information");
    }
    In the Main Assistant scene put :
    Code:
    <div id="Item"></div>
    The My_File.json looks like:
    Code:
    {
        "Item": "Here is the description of Item"
    }
    Note that the json file is stored on the folder "Database" of your application path.

    if you want more items, just add them in the json file and add IDs in the scene
    _________________________________________________________
    Ze-Palm
    is ZE #1 innovative software solutions for PalmOS and Palm webOS.


    _________________________________________________________[/COLOR]
  6.    #6  
    I'm trying to get data from an XHTML page so I need the request to return something that either can be turned into or already is a DOM document. Thanks though, as Ajax.Request will still be more convenient for when I'm dealing with JSON.
  7. #7  
    try setting 'evalJSON: false'
    danNielson.com - Slalom - twitter - facebook
    A posted thanks dies with the thread. Clicking the button lasts until the admins get bored with this site and throw it in the recycling bin.

Posting Permissions