|
|
|
สอบถามปัญหา เมื่อ คิวรี่ ข้อมูลออกมาแสดงใน textbox เเล้วต้องการส่งไปให้ ajax แต่ว่ามันส่งได้แต่ ข้อมูลที่ คิวรี่ออกมาได้ตัวแรก |
|
|
|
|
|
|
|
test1.php
<html>
<head>
<script type="text/javascript" src="docallajax1.js"></script>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Check</title>
</head>
<body>
<form name="frmMain">
<table width="274" border="1">
<tr>
<th width="117">
<div align="center">usidemp</div></th>
<th><input type="text" name="usidemp" id="usidemp" size="20"></th>
</tr>
</table>
<br>
<input name="Login" type="button" id="Login" OnClick="JavaScript:doCallAjax();" value="Check">
</form>
<span id="mySpan">
</span>
</body>
</html>
test2.php
<?php
session_start();?> <script type="text/javascript" src="docallajax2.js"></script><?
$usidemp = trim($_POST["tusidemp"]);
//*** Check usidemp ***//
if(trim($usidemp) == "")
{
echo "<font color=red>**</font> Plase input [usidemp]";
exit();
}
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("emp_db");
mysql_query("SET NAMES UTF8");
//*** Check usidemp ***//
$strSQL = "SELECT * FROM detail WHERE usidemp = '".$usidemp."' ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$objNumrow = mysql_num_rows($objQuery);
if ($objNumrow !=0){
while ($objResult = mysql_fetch_array($objQuery))
{
echo "<font color=blue>".$objResult["usname"]."    ".$objResult["ussurname"]."</font>" ?>
<form name="frm">
<input type="hidden" name="ususer" id="ususer" size="20" value="<?=$objResult["usid"] ?>" />
<input name="btnReset" type="button" id= "btnsubmit" OnClick="JavaScript:doCallAjax2();" value="Reset"> <BR>
</form>
<?
$i++;
}
}
else{
echo "<font color=red>**</font>ข้อมูลผิด";
}
mysql_close($objConnect);
?>
Test2.php
<?php
session_start(); ?>
<script type="text/javascript" src="docallajax2.js"></script><?
$usidemp = trim($_POST["tusidemp"]);
$usid = $_POST["usid"];
$val = "666666666656566";
$chr16 = md5($val);
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("emp_db");
mysql_query("SET NAMES UTF8");
$strSQL = "SELECT * FROM detail WHERE usidemp = '".$usidemp."' ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
//*** Check usidemp ***//
if($usidemp&&$ususer != ""){
$strSQL2 = "UPDATE detail SET uspass = '".$chr16."' WHERE usidemp = '".$usidemp."' AND usid = '".$usid."' ";
$objQuery2 = mysql_query($strSQL2) or die ("Error Query [".$strSQL2."]");
echo"<span id='mySpan'> </span>Sucsesfull";
}
else{
echo " can't chang password";
}
mysql_close($objConnect);
?>
doCallAjax
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 = 'test2.php';
var pmeters = "tusidemp=" + encodeURI( document.getElementById("usidemp").value );
HttPRequest.open('POST',url,true);
HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=Windows-874");
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
{
document.getElementById("mySpan").innerHTML = HttPRequest.responseText;
}
}
}
// JavaScript Document
doCallAjax2
var HttPRequest = false;
function doCallAjax2() {
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 = 'test3.php';
var pmeters = "tusidemp=" + encodeURI( document.getElementById("usidemp").value)+
"&usid=" + encodeURI( document.getElementById("usid").value);
HttPRequest.open('POST',url,true);
HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=Windows-874");
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
{
document.getElementById("mySpan").innerHTML = HttPRequest.responseText;
}
}
}
คือพอผมเช็ค รหัสพนักงาน เสดปุ๊บ มันจะโชว์ user ของพนักงานทั้งหมด และที นี้ปัญหาคือพอผมกด รีเสทรหัสคนที่สอง มันกับไปรีเสทแต่ คนแรกอะคับ
Tag : PHP, MySQL, Ajax, CakePHP
|
|
|
|
|
|
Date :
2012-07-06 02:11:51 |
By :
nut |
View :
1081 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ปิดกะทู้แกไขได้ละครับ
|
|
|
|
|
Date :
2012-07-06 05:30:32 |
By :
nut |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|