Hi i was trying to to do login page in titanium.In that im using aspx page to fetch values from sql server.bt it is nt cmg fr me can any one help plz and here is my code var curWindow = Titanium.UI.currentWindow; var scrollView = Titanium.UI.createScrollView({ contentWidth:'auto', contentHeight:'auto', top:0, showVerticalScrollIndicator:true, showHorizontalScrollIndicator:true }); var view = Titanium.UI.createView({ width:"100%", height: "auto", top:10, paddingBottom: 15 });
var lbl_User = Titanium.UI.createLabel({
text:'Username:',
height:30,
width:"98%",
color:'#222',
font: {fontSize:16},
top: 10
});
var txt_User = Titanium.UI.createTextField({
width: "98%",
color: "#222",
paddingLeft: 5,
border: 1,
hintText:'Username',
borderColor: "gray",
borderRadius: 3,
font:{fontSize:16},
height: 40,
top: 40,
keyboardType:Titanium.UI.KEYBOARD_DEFAULT,
returnKeyType:Titanium.UI.RETURNKEY_DEFAULT,
borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});
var lbl_Pass = Titanium.UI.createLabel({
text:'Password:',
height:30,
width:"98%",
color:'#222',
font:{fontSize:16},
top: 90
});
var txt_Pass = Titanium.UI.createTextField({
width: "98%",
color: "#222",
paddingLeft: 5,
border: 1,
hintText:'Password',
borderColor: "gray",
borderRadius: 3,
passwordMask: true,
font:{fontSize:16},
height: 40,
top: 120,
keyboardType:Titanium.UI.KEYBOARD_DEFAULT,
returnKeyType:Titanium.UI.RETURNKEY_DEFAULT,
borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});
var btn_Login = Titanium.UI.createButton({
color: "#555",
width:90,
height:35,
top:180,
borderRadius:1,
font:{fontFamily:'Arial',fontWeight:'bold',fontSize:14} ,
title: "Log In"
});
var details = Titanium.Network.createHTTPClient();
btn_Login.addEventListener("click",function(e){
if(txt_User.value != '' && txt_Pass.value != '')
{
details.open("POST","http://localhost:53541/WebSite1/Default.aspx?uname='"+txt_User.value +"'& pwd='"+txt_Pass.value+"'");
alert("Sucessfully Login");
}
else
{
alert("Username/Password required");
}
});
details.onload = function()
{
} view.add(lbl_User); view.add(txt_User); view.add(lbl_Pass); view.add(txt_Pass); view.add(btn_Login); scrollView.add(view);
curWindow.add(scrollView);
2 Answers
This is what I did on my older app:
var win = Ti.UI.currentWindow; var loginURL = "http://localhost:53541/WebSite1/"; var conn = true; if (Titanium.Network.networkType === Titanium.Network.NETWORK_NONE) { conn = false; } // Username var username = Ti.UI.createTextField({ color: '#336699', top: 10, left: 10, width: 300, height: 40, hintText: 'Username', autocorrect:false, keyboardType:Ti.UI.KEYBOARD_DEFAULT, returnKeyType: Ti.UI.RETURNKEY_DEFAULT, borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED, value:'mj' }); win.add(username); // Password var password = Ti.UI.createTextField({ color: '#336699', top: 60, left: 10, width: 300, height: 40, hintText: 'Password', autocorrect:false, passwordMask:true, keyboardType:Ti.UI.KEYBOARD_DEFAULT, returnKeyType: Ti.UI.RETURNKEY_DEFAULT, borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED, value:'PA$$word' }); win.add(password); // Login button var loginBtn = Ti.UI.createButton({ title:'Login', top:220, width:90, height:35, borderRadius:1, font:{ fontFamily:'Arial', fontWeight:'bold', fontSize:14 } }); win.add(loginBtn); var loginReq = Titanium.Network.createHTTPClient(); loginBtn.addEventListener('click',function(e){ if(conn){ if (username.value !== '' && password.value !== ''){ loginReq.open("POST",loginURL+"Default.aspx"); var params = { username: username.value, password: password.value, login: true }; loginReq.send(params); } else { alert("All fields are required"); } } else { alert("A connection to the internet is required!"); } }); loginReq.onload = function(){ Ti.API.info('Logging in'); var json = this.responseText; var response = JSON.parse(json); if (response.logged === true){ username.blur(); password.blur(); Ti.App.fireEvent('grantEntrance', { name:response.name, email:response.email }); win.close(); Ti.App.Properties.setString("user_id", response.user_id); Ti.App.Properties.setString("username", response.name); Ti.App.Properties.setString("email", response.email); } else { alert(response.message); } }; loginReq.onerror = function() { Ti.API.error(this.status + ' - ' + this.statusText); };
you should change:
details.open("POST", "http://localhost:53541/WebSite1/Default.aspx?uname='" + txt_User.value + "'& pwd='" + txt_Pass.value + "'");with
details.open("POST", "http://localhost:53541/WebSite1/Default.aspx"); var params = {}; params.uname = txt_User.value; params.pwd = txt_Pass.value; details.send(params);
Your Answer
Think you can help? Login to answer this question!