Eamorr
Eamorr

Reputation: 10022

Appcelerator change button text

Greetings,

I'm trying to change the text on a button in appcelerator.

Now I can change it once, but I can't change the text back once some event occurs.

Here is the code:

var login=Titanium.UI.createButton({
   title:'Login',
     width:250,
     top:330
});
win.add(login);
var xhr=Titanium.Network.createHTTPClient();
login.addEventListener('click', function(e){
     login.title="Please wait...";   //this line works fine
     xhr.onload=function(){
            login.title="Login";   //this line doesn't work
            if(uname.hasText){
                 uname.value=this.responseText;
            }
     };
     xhr.onerror=function(){
            login.title="Login";   //this line doesn't work
            alertDialog.show();
     };
     xhr.open("POST","http://www.asdf.com/ajax/login.php");
     if(uname.hasText && pword.hasText){
            xhr.send({"uname":uname.value,"pword":pword.value});
     }else{
            alertDialog.show();
     }
});

I simply don't know what to do at this point!

Any insight greatly appreciated.

Many thanks in advance,

Upvotes: 1

Views: 1446

Answers (1)

Aaron Saunders
Aaron Saunders

Reputation: 33345

you should create the HTTPClient inside the eventListener

login.addEventListener('click', function(e){
    var xhr=Titanium.Network.createHTTPClient();
     xhr.onload=function(){};
     xhr.onerror =function(){};
     xhr.onreadysetstate =function(){};
}

Upvotes: 0

Related Questions