|
|
|
รบกวนดู code ให้หน่อยครับ login ใน phonegap ครับ ต้องการใช้ด่วนเลยครับ ขอบคุณมากครับ |
|
|
|
|
|
|
|
รบกวนดู code ชุดนี้ให้หน่อยนะครับ login ไม่ผ่านครับ นั่งงมมาหลายวันแล้ว
Code (PHP)
<body onload="init()">
<div id="launcherPage" data-role="page">
<!-- I'm just here waiting for deviceReady -->
</div>
<div id="loginPage" data-role="page">
<div data-role="header">
<h1>Auth Demo</h1>
</div>
<div data-role="content">
<form id="loginForm">
<div data-role="fieldcontain" class="ui-hide-label">
<label for="username">Username:</label>
<input type="text" name="username" id="username" value="" placeholder="Username" />
</div>
<div data-role="fieldcontain" class="ui-hide-label">
<label for="password">Password:</label>
<input type="password" name="password" id="password" value="" placeholder="Password" />
</div>
<input type="submit" value="Login" id="submitButton">
</form>
</div>
<div data-role="footer">
<h4>© Camden Enterprises</h4>
</div>
</div>
</body>
อันนี้ไฟล์ js นะครับ
Code (Java)
function handleLogin() {
var form = $("#loginForm");
//disable the button so we can't resubmit while we wait
$("#submitButton",form).attr("disabled","disabled");
var u = $("#username", form).val();
var p = $("#password", form).val();
if(u != '' && p!= '') {
//$.post("http://www.coldfusionjedi.com/demos/2011/nov/10/service.cfc?method=login&returnformat=json", {username:u,password:p}, function(res) {
$.post("json.php?method=login&returnformat=json", {username:u,password:p}, function(res) {
if(res == true) {
//store
window.localStorage["username"] = u;
window.localStorage["password"] = p;
$.mobile.changePage("some.html");
} else {
navigator.notification.alert("Your login failed", function() {});
}
$("#submitButton").removeAttr("disabled");
},"json");
} else {
navigator.notification.alert("You must enter a username and password", function() {});
$("#submitButton").removeAttr("disabled");
}
return false;
}
ไฟล์ php ที่ server นะครับ
Code (PHP)
<?php
header('Content-type: application/json');
$server = "localhost";
$username = "root";
$password = "";
$database = "test9";
$con = mysql_connect($server, $username, $password) or die ("Could not connect: " . mysql_error());
mysql_select_db($database, $con);
$sql = "SELECT * FROM tstudent ORDER BY FPASSWORD ASC";
$result = mysql_query($sql) or die ("Query error: " . mysql_error());
$records = array();
while($row = mysql_fetch_assoc($result)) {
$records[] = $row;
}
mysql_close($con);
echo $_GET['jsoncallback'] . '(' . json_encode($records) . ');';
?>
รบกวนด้วยครับ มือใหม่ java ยังงง อยู่มากๆครับ ขอบคุณครับ
Tag : MySQL, HTML/CSS, Ajax, iOS, JAVA
|
ประวัติการแก้ไข 2012-12-26 08:21:33
|
|
|
|
|
Date :
2012-12-26 08:19:36 |
By :
eak302 |
View :
1219 |
Reply :
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
คุณรันผ่าน Web Browser ได้ปกติหรือเปล่าครับ
|
|
|
|
|
Date :
2012-12-26 11:18:33 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
รันในเว็บไม่ไปครับ แต่ยังไม่ได้ลอง run บน xcode ครับ ไม่ทราบว่าผมเขียน ตัวแปร json หรือ java ไม่ตรงกันหรือป่าวครับ
รบกวนหน่อยนะครับ
|
|
|
|
|
Date :
2012-12-26 11:36:07 |
By :
eak302 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
มันจะต้องรันบนเว็บให้ผ่านก่อนน่ะครับ
|
|
|
|
|
Date :
2012-12-26 11:40:09 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
รบกวนช่วยดู CODE ให้หน่อยได้ไหมครับว่า CODE ถูกหรือเปล่า
Code (Java)
function handleLogin() {
var form = $("#loginForm");
//disable the button so we can't resubmit while we wait
$("#submitButton",form).attr("disabled","disabled");
var u = $("#username", form).val();
var p = $("#password", form).val();
if(u != '' && p!= '') {
//$.post("http://www.coldfusionjedi.com/demos/2011/nov/10/service.cfc?method=login&returnformat=json", {username:u,password:p}, function(res) {
$.post("json.php?method=login&returnformat=json", {username:u,password:p}, function(res) {
if(res == true) {
//store
window.localStorage["username"] = u;
window.localStorage["password"] = p;
$.mobile.changePage("some.html");
} else {
navigator.notification.alert("Your login failed", function() {});
}
$("#submitButton").removeAttr("disabled");
},"json");
} else {
navigator.notification.alert("You must enter a username and password", function() {});
$("#submitButton").removeAttr("disabled");
}
return false;
}
ส่งค่ากลับมาถูกหรือเปล่า ขอบคุุณครับ พี่วิน
|
|
|
|
|
Date :
2012-12-26 11:44:50 |
By :
eak302 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ให้ผมดูแบบนี้ผมดูไม่เป็นครับ
|
|
|
|
|
Date :
2012-12-26 11:50:13 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ไฟล์ database ครับ
MySQL Database
CREATE TABLE `tstudent` (
`FRUN` char(15) NOT NULL DEFAULT '',
`FMASTER` char(15) DEFAULT NULL,
`FCODE` char(15) NOT NULL DEFAULT '',
`FNAME` varchar(100) DEFAULT NULL,
`FSURNAME` varchar(100) DEFAULT NULL,
`FENG_NAME` varchar(100) DEFAULT NULL,
`FENG_SURNAME` varchar(100) DEFAULT NULL,
`FUSERNAME` varchar(50) DEFAULT NULL,
`FPASSWORD` varchar(50) DEFAULT NULL,
`FEMAIL` varchar(100) DEFAULT NULL,
`FMOBILE` varchar(15) DEFAULT NULL,
`FSCHOOL` varchar(15) DEFAULT NULL,
`FTITLE` varchar(15) DEFAULT NULL,
`FTHAI_ID` varchar(15) DEFAULT NULL,
`FADDRESS` varchar(100) DEFAULT NULL,
`FBRANCH` varchar(15) DEFAULT '99',
`FPICTURE` varchar(150) DEFAULT NULL,
`FMACHINE` varchar(15) DEFAULT NULL,
`FEXPIRE_TIME` varchar(20) DEFAULT NULL,
`FPHONE` char(15) DEFAULT NULL,
`FBLACKLIST` char(1) DEFAULT NULL,
`FBLACKLIST_REMARK` char(200) DEFAULT NULL,
`FSERIAL` char(15) DEFAULT NULL,
`FSECTION` varchar(15) DEFAULT NULL,
`FPROVINCE` char(15) DEFAULT NULL,
`flogin_verify` char(15) DEFAULT NULL,
PRIMARY KEY (`FRUN`),
UNIQUE KEY `FCODE` (`FCODE`),
UNIQUE KEY `FUSERNAME` (`FUSERNAME`)
) ENGINE=InnoDB DEFAULT CHARSET=tis620;
INSERT INTO `tstudent` (`FRUN`, `FMASTER`, `FCODE`, `FNAME`, `FSURNAME`, `FENG_NAME`, `FENG_SURNAME`, `FUSERNAME`, `FPASSWORD`, `FEMAIL`, `FMOBILE`, `FSCHOOL`, `FTITLE`, `FTHAI_ID`, `FADDRESS`, `FBRANCH`, `FPICTURE`, `FMACHINE`, `FEXPIRE_TIME`, `FPHONE`, `FBLACKLIST`, `FBLACKLIST_REMARK`, `FSERIAL`, `FSECTION`, `FPROVINCE`, `flogin_verify`) VALUES('0107462900003', NULL, '09080001', 'ชลธิชา', 'อนันตสุข', 'CHONTHICHA', 'ANANTASUK', 'CHONTHICHA.ANA', '42254 ', '[email protected]', '0870019468', '000005', 'นางสาว', '1101401947147', '15/2 ถ.บางนา-ตราด ', '06', '09080001.jpg', '', '', '023167251', NULL, NULL, '005722', '00189', NULL, NULL);
index.html
<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Auth Demo 2</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/latest/jquery.mobile.min.css" />
<script type="text/javascript" charset="utf-8" src="cordova-1.8.1.js"></script>
<script src="jquery.mobile/jquery-1.7.2.min.js"></script>
<script src="jquery.mobile/jquery.mobile-1.1.0.min.js"></script>
<script src="main.js"></script>
</head>
<body onload="init()">
<div id="launcherPage" data-role="page">
<!-- I'm just here waiting for deviceReady -->
</div>
<div id="loginPage" data-role="page">
<div data-role="header">
<h1>Auth Demo</h1>
</div>
<div data-role="content">
<form id="loginForm">
<div data-role="fieldcontain" class="ui-hide-label">
<label for="username">Username:</label>
<input type="text" name="username" id="username" value="" placeholder="Username" />
</div>
<div data-role="fieldcontain" class="ui-hide-label">
<label for="password">Password:</label>
<input type="password" name="password" id="password" value="" placeholder="Password" />
</div>
<input type="submit" value="Login" id="submitButton">
</form>
</div>
<div data-role="footer">
<h4>© Camden Enterprises</h4>
</div>
</div>
</body>
</html>
main.js
function init() {
document.addEventListener("deviceready", deviceReady, true);
delete init;
}
function checkPreAuth() {
console.log("checkPreAuth");
var form = $("#loginForm");
if(window.localStorage["username"] != undefined && window.localStorage["password"] != undefined) {
$("#username", form).val(window.localStorage["username"]);
$("#password", form).val(window.localStorage["password"]);
handleLogin();
}
}
function handleLogin() {
var form = $("#loginForm");
//disable the button so we can't resubmit while we wait
$("#submitButton",form).attr("disabled","disabled");
var u = $("#username", form).val();
var p = $("#password", form).val();
if(u != '' && p!= '') {
//$.post("http://www.coldfusionjedi.com/demos/2011/nov/10/service.cfc?method=login&returnformat=json", {username:u,password:p}, function(res) {
$.post("http://localhost/server.php?method=login&returnformat=json", {username:u,password:p}, function(res) {
if(res == true) {
//store
window.localStorage["username"] = u;
window.localStorage["password"] = p;
$.mobile.changePage("some.html");
} else {
navigator.notification.alert("Your login failed", function() {});
}
$("#submitButton").removeAttr("disabled");
},"json");
} else {
navigator.notification.alert("You must enter a username and password", function() {});
$("#submitButton").removeAttr("disabled");
}
return false;
}
function deviceReady() {
console.log("deviceReady");
$("#loginPage").on("pageinit",function() {
console.log("pageinit run");
$("#loginForm").on("submit",handleLogin);
checkPreAuth();
});
$.mobile.changePage("#loginPage");
}
server.php
<?php
header('Content-type: application/json');
$server = "localhost";
$username = "root";
$password = "";
$database = "test9";
$con = mysql_connect($server, $username, $password) or die ("Could not connect: " . mysql_error());
mysql_select_db($database, $con);
//Check Input
if (!isset($_POST['username']) || !isset($_POST['password'])) {
$json = array('status' => 'failed');
echo json_encode($json);
exit();
}
if (!isset($_GET['username']) || !isset($_GET['password'])) {
$json = array('status' => 'failed');
echo json_encode($json);
exit();
}
//$user = "CHONTHICHA.ANA";
//$pass = "42254";
$sql = 'SELECT * FROM tstudent WHERE FUSERNAME = "'.$user.'" AND FPASSWORD = "'.$pass.'"';
$result = mysql_query($sql) or die ("Query error: " . mysql_error());
if ($result) {
//echo "success";
}
$user = mysql_fetch_array($result);
mysql_close($con);
//Login Success
$json = array('status' => 'success');
//echo "success";
echo json_encode($json);
exit(0);
//Have not user or password incorrect
if (empty($user)) {
$json = array('status' => 'failed');
//echo "success";
echo json_encode($json);
exit(0);
}
?>
ประมาณนี้อะครับ รบกวนด้วยนะครับ
ขอบคุณมากๆครับ
|
|
|
|
|
Date :
2012-12-26 12:09:28 |
By :
eak302 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|