|
|
|
ajax ภาษาไทย จากโค้ดที่มีในเว็บ ไม่ทราบว่า ทำอย่างไรให้หน้าแรกที่แสดงขึ้นมาว่า คุณยังไม่ได้กรอกชื่อผู้ใช้งาน |
|
|
|
|
|
|
|
จากโค้ดที่มีในเว็บ ไม่ทราบว่า ทำอย่างไรให้หน้าแรกที่แสดงขึ้นมาว่า คุณยังไม่ได้กรอกชื่อผู้ใช้งาน คุณยังไม่ได้กรอกรหัสผ่านเป็นภาษาไทยได้ครับ รบกวนช่วยดูให้หน่อย
ajaxphploginform1.php
<?php
/*** By Weerachai Nukitram***/
/*** http://www.ThaiCreate.Com ***/
?>
<html>
<head runat="server" >
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title></title>
<script language="JavaScript">
var HttPRequest = false;
function doCallAjax() {
HttPRequest = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
HttPRequest = new XMLHttpRequest();
if (HttPRequest.overrideMimeType) {
HttPRequest.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
HttPRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
HttPRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!HttPRequest) {
alert('Cannot create XMLHTTP instance');
return false;
}
var url = 'AjaxPHPLoginForm2.php';
var pmeters = "tUsername=" + encodeURI( document.getElementById("txtUsername").value) +
"&tPassword=" + encodeURI( document.getElementById("txtPassword").value );
HttPRequest.open('POST',url,true);
HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
HttPRequest.setRequestHeader("Content-length", pmeters.length);
HttPRequest.setRequestHeader("Connection", "close");
HttPRequest.send(pmeters);
HttPRequest.onreadystatechange = function()
{
if(HttPRequest.readyState == 3) // Loading Request
{
document.getElementById("mySpan").innerHTML = "Now is Loading...";
}
if(HttPRequest.readyState == 4) // Return Request
{
if(HttPRequest.responseText == 'Y')
{
window.location = 'AjaxPHPLoginForm3.php';
}
else
{
document.getElementById("mySpan").innerHTML = HttPRequest.responseText;
}
}
}
}
</script>
<body>
<h1>Login Form</h1>
<form name="frmMain">
<span id="mySpan"></span>
<table width="274" border="1">
<tr>
<th width="117">
<div align="left">Username</div></th>
<th><input type="text" name="txtuUsername" id="txtUsername" size="20"></th>
</tr>
<tr>
<th width="117">
<div align="left">Password</div></th>
<th><input type="password" name="txtPassword" id="txtPassword" size="20"></th>
</tr>
</table>
<br>
<input name="btnLogin" type="button" id="btnLogin" OnClick="JavaScript:doCallAjax();" value="Login">
</form>
</body>
</html>
ajaxphploginform2.php
<?php
/*** By Weerachai Nukitram ***/
/*** http://www.ThaiCreate.Com ***/
session_start();
$strUsername = trim($_POST["tUsername"]);
$strPassword = trim($_POST["tPassword"]);
//*** Check Username ***//
if(trim($strUsername) == "")
{
echo "<font color=red>**</font> กรุณากรอกชื่อผู้ใช้งาน"; // ให้ไปขึ้นฟอร์มแรก เป็นภาษาไทย
exit();
}
//*** Check Password ***//
if(trim($strPassword) == "")
{
echo "<font color=red>**</font> กรุณากรอกรหัสผ่าน"; // ให้ไปขึ้นฟอร์มแรก เป็นภาษาไทย
exit();
}
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
//*** Check Username & Password ***//
$strSQL = "SELECT * FROM account WHERE Username = '".$strUsername."' and Password = '".$strPassword."' ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$objResult = mysql_fetch_array($objQuery);
if($objResult)
{
echo "Y";
//*** Session ***//
$_SESSION["Username"] = $strUsername;
session_write_close();
}
else
{
echo "<font color=red>**</font> ชื่อผู้ใช้งานหรือรหัสผ่านผิดพลาด"; // ให้ไปขึ้นฟอร์มแรก เป็นภาษาไทย
}
mysql_close($objConnect);
?>
ajaxphploginform3.php
<?php
/*** By Weerachai Nukitram ***/
/*** http://www.ThaiCreate.Com ***/
session_start();
if($_SESSION["Username"] == "")
{
header("location:AjaxLoginForm.html");
exit();
}
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$strSQL = "SELECT * FROM account WHERE Username = '".$_SESSION["Username"]."' ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$objResult = mysql_fetch_array($objQuery);
?>
<html>
<head>
<title>ThaiCreate.Com Ajax Tutorial</title>
</head>
<body>
<h1>Welcome [<?=$objResult["Name"];?>] to My Website</h1>
</body>
</html>
Tag : - - - -
|
|
|
|
|
|
Date :
2009-12-04 15:46:32 |
By :
nae |
View :
1076 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
มันขึ้นอย่างนี้อะครับ
|
|
|
|
|
Date :
2009-12-04 16:22:21 |
By :
nae |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผมว่านะครับถ้าเป็นการตรวจสอบว่าใส่ยูสเซอร์หรือรหัสผ่าน ยังใช้แค่จาวาสคริบ ตรวจก่อนก็ได้มั้ง ถ้า textbox ว่างก็แสดงข้อความเลยไม่ต้องไปตรวจสอบที่อีกไฟล์ก็ได้นะ
หรือว่าถ้าจะทำแบบนี้จริงๆข้อความที่ส่งมาก็ลอง encode ก่อนแล้วค่อยมา decode ที่หน้าแรกแล้วค่อยแสดง
หรือใส่นี่ เข้าไปที่ ajaxphploginform2.php
Code (PHP)
header("Content-Type: text/html; charset=utf-8");//ทำให้แสดงข้อความที่เป็นภาษาไทยได้
|
|
|
|
|
Date :
2009-12-05 14:02:57 |
By :
naskw |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|