I am new with titanium and i was just trying out one of the login tutorials i got online and i run into "runtime error uncaught syntaxerror:Unexpected token <" problem the tutorial is from mobile.tutsplus.com. everything works perfect but every-time i send the information to the server i get the error response. If I hardcode the values that I put in the form everything works fine. Any ideas?
$username = “Dave”; $password = “Dave”; //instead of $username = $_POST['user']; $password = $_POST['pass'];The following is my code can anyone help thank you
app.js
// this sets the background color of the master UIView (when there are no windows/tab groups on it) Titanium.UI.setBackgroundColor('#fff'); var tabGroup = Titanium.UI.createTabGroup(); var login = Titanium.UI.createWindow({ title:'User Authentication Demo', tabBarHidden:true, url:'main_windows/login.js' }); var loginTab = Titanium.UI.createTab({ title:"Login", window:login }); tabGroup.addTab(loginTab); tabGroup.open();login.js
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, borderColor: "gray", borderRadius: 3, font:{fontSize:16}, height: 40, top: 40 }); 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, borderColor: "gray", borderRadius: 3, passwordMask: true, font:{fontSize:16}, height: 40, top: 120 }); var btn_Login = Titanium.UI.createButton({ width: "98%", color: "#555", font:{fontSize: 22, fontWeight: "bold"}, height: 50, top: 180, title: "Log In" }); function getUserInfo(e){ var user = txt_User.value; var pass = txt_Pass.value loginUser(user,pass); } btn_Login.addEventListener('click',getUserInfo); /* * Login Event Handling */ var loginReq = Titanium.Network.createHTTPClient(); loginReq.setTimeout(15000); loginReq.onload = function() { var json = this.responseText; var response = JSON.parse(json); if (response.logged == true) { alert("Welcome " + response.name + ". Your email is: " + response.email); } else { alert(response.message); } }; loginReq.onerror = function() { alert("Network error"); }; function loginUser(user,pass){ if (user != '' && pass != '') { loginReq.open("POST","http://192.168.1.134/post_auth.php"); var params = { username: user, password: Ti.Utils.md5HexDigest(pass) }; loginReq.send(params); } else { alert("Username/Password are required"); } } 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);the PHP file
<?php // Select your MySQL host, username and password $con = mysql_connect('localhost','root','A712660@caritas'); if (!$con) { echo "Failed to make connection."; exit; } // Select the database. Enter the name of your database (not the same as the table name) $db = mysql_select_db('app'); if (!$db) { echo "Failed to select db."; exit; } $username = $_POST['user']; $password = $_POST['pass']; $sql = "SELECT * FROM users WHERE username = '" . $username . "' AND password = '" . $password . "'"; $query = mysql_query($sql); if (mysql_num_rows($query) > 0) { $row = mysql_fetch_array($query); $response = array( 'logged' => true, 'name' => $row['name'], 'email' => $row['email'] ); echo json_encode($response); } else { $response = array( 'logged' => false, 'message' => 'Invalid Username and/or Password' ); echo json_encode($response); } ?>
Your Answer
This question has been locked and cannot accept new answers.