2010-11-10 185 views
1

问候,Appcelerator更改按钮文本

我试图更改appcelerator中的按钮上的文本。

现在我可以更改一次,但一旦发生某些事件后我无法更改文本。

下面是代码:

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(); 
    } 
}); 

我根本不知道该怎么在这一点上做的!

任何有识之士非常感谢。

提前许多感谢,

回答

0

你应该创建HttpClient的内部事件监听

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

嘿,我试过了,我仍然无法改变内xhr.onload文本=函数(){ } – Eamorr 2010-11-15 17:29:24

+0

可以发布更新后的代码吗? – 2010-11-15 17:55:35