Results 1 to 2 of 2
  1.    #1  
    I am new to webos development and thought I'd do something simple to access a webserver microblogging tool in my company. For some reason the ajax calls succeed but I don't ever see the results on the server.

    Do you see anything wrong with this code? Any insight appreciated.

    This gets logged in...

    new Ajax.Request(
    "https://watercooler.insertcompanynamehere.com/login",
    {
    method : "get", evalJSON : "force",
    parameters : {
    'sea' : this.models.txtUsername.value,
    'password':this.models.txtPassword.value
    },
    onSuccess : function(inTransport) {
    // Account verified
    appAssistant.tempAccountInfo = {
    username : this.models.txtUsername.value,
    password : this.models.txtPassword.value
    };
    }.bind(this),

    onFailure : function(inTransport) {
    // Failure while verifying account.
    this.resetButton();
    Mojo.Controller.errorDialog("Unable to verify account. " +
    "Please check entered credentials and try again."
    );
    }.bind(this),

    onException : function(inTransport, inException) {
    // Exception while verifying account.
    Mojo.Controller.errorDialog("EXCEPTION: " + inException);
    }.bind(this)

    }


    This sends the status:
    new Ajax.Request(
    "https://watercooler.insertcompanynamehere.com/status.update",
    {
    method : 'post', evalJSON : "force",
    parameters : {
    'update' : 'testing...'
    },
    onSuccess : Mojo.Controller.stageController.swapScene("settings"),
    onFailure : function(inTransport) {
    // Failure while getting friends list.
    this.resetButton();
    Mojo.Controller.errorDialog("failure setting status: " +
    inTranspot.responseText);
    }.bind(this),
    onException : function(inTransport, inException) {
    // Exception while getting friends list.
    Mojo.Controller.errorDialog("Exeception setting status: " + inException);
    }.bind(this)
    }
  2. #2  
    First and foremost:

    onSuccess merely says that it connected to the server. It doesn't say that you got a 200 reply (OK), it could be a 403 (unauthorized), 404 (not found), or even 500 (server error). You should verify the response code to ensure it is 200/30x.

    Secondly:

    You need to be sure you're calling the status update after the login is done. The way Ajax.Request() works is in an asynchronous manner. The way it calls your onSuccess() function is asynchronous.

    An example of async vs sync:

    (works in a web browser, not webOS)
    sync:
    Code:
    alert("Val1");
    // execute some various code
    alert("Val2");
    alert("Val3");
    async:
    Code:
    function someFunction(callback) {
         // execute some various code
         callback();
    }
    
    alert("Val1");
    someFunction(function() {
         alert("Val3");
    }.bind(this));
    alert("Val2");
    Basically, if you have 2 Ajax.Request() calls back to back, they'll both be executing at the same time.

    So what you need to be sure of is that your code for login is done before you update the status. You could do this by setting a global variable of "loggedIn" or something similar and check that before doing a status update.
    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

Posting Permissions