|
 |
|
ขอคำแนะนำเรื่อง AJAX ใน PHP ด้วยค่ะ ปุ่มมันไม่ยอมทำงาน |
|
 |
|
|
 |
 |
|
ใช้ AJax ตาม tutorials ทีเ่ป็นหน้า Load web อ่าค่ะ
ลองมาปรับปรุงใช้กับงาน ซึ่งอีก page มันก็มี ajax อยู่ เป็นไปได้ไหมคะ ที่จะมีการซ้ำซ้อนกันของ scripts ทำให้เรียกใช้งานไม่ได้ ดูโค้ตเลยค่ะ
ส่วนของหน้าหลัก
<script language="JavaScript">
var HttPRequest = false;
function reLoad (url) {
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 pmeters = "";
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
{
document.getElementById('mySpan').innerHTML = HttPRequest.responseText;
}
}
}
</script>
<body Onload="JavaScript:reLoad('test.php');">
<div align ="center"><table width="1050" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="150" valign="top" align="center"><a href="JavaScript:reLoad('test.php');">หนัาหลัก</a></td> /// ส่วนนี้ค่ะที่ต้องเรียกใช้งาน ///
<td width="150" valign="top" align="center"><a href="JavaScript:reLoad('verificationx.php');">ตรวจสอบลายมือชื่อ</a></td>
<td width="150" valign="top" align="center"><a href="JavaScript:reLoad('u_setting.php');">แก้ไขข้อมูล</a></td>
<td width="150" valign="top" align="center"><a href="JavaScript:reLoad('popup_register.php');">ลงทะเบียน</a></td>
<td width="150" valign="top" align="center"><a href="JavaScript:reLoad('preupload_search.php');">แสดงไฟล์</a></td>
<td width="150" valign="top" align="center"><a href="index.html">ออกจากระบบ</a></td>
</tr>
<tr>
<td colspan="4" valign="top"><span id="mySpan"></span></td>
</tr>
</table></div>
</body>
</html>
อันนี้ส่วนของอีก page ชื่อไฟล์ test ตามที่เรียกใช้งาน
ไฟล์นี้ลองเรียกใช้งานเดี่ยวๆมันทำงานตามเงื่อนไขค่ะ แต่พอมาเรียกพร้อมกับ reLoad ตัวบนมันไม่ทำงานค่ะ
<script language="JavaScript">
var HttPRequest = false;
function check() {
HttPRequest = false;
test = 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 = 'preupload_check.php';
var pmeters = "tUsername=" + encodeURI( document.getElementById("filename").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("check").innerHTML = "";
}
if(HttPRequest.readyState == 4) // Return Request
{
if(HttPRequest.responseText == 'yes')
document.getElementById('upload').disabled = true;
}
else
{
document.getElementById('upload').disabled = false;
}
}
}
</script>
<table width="600" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="780" height="" colspan="4" align="center"></td>
<?
@session_start();
@$_SESSION['username']="$username";
?> </p>
<p> </p>
<p> <span class="style5">
<?
echo"<b>Login as : $username</b>";
?>
<? $time = date("Y-m-d");?>
<? $gettime = date("H:i:s");?>
</span></p>
<table width="532" align="center" >
<tr>
<td align="left" valign="top" class="mainContent" >
<form method="post" action ="nusr_upload1.php" enctype="multipart/form-data">
<div align="center">
<a align="left" class="style2">ไฟล์อ้างอิง</a>
<input type="text" name="filename" id="filename" OnChange="JavaScript:check();"/>
<input name="btnRegister" type="button" id="btnRegister" value="ตรวจสอบ"></input>
<span id="check"> </span>
<input type="hidden" name="MAX_FILE_SIZE" value="5000000" />
<input name="userfile" type="file" id="userfile" />
<input name="upload" type="submit" class="box" id="upload" value="ทำการอัพโหลดไฟล์" />
</div>
</form>
</td>
</tr>
</table>
ขอคำแนะนำจากทุกท่านด้วยค่ะ
Tag : PHP, Ajax

|
|
 |
 |
 |
 |
Date :
2010-10-14 21:13:58 |
By :
mzchewiize |
View :
905 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
|
 |
 |
 |
 |
Date :
2010-10-14 21:49:36 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่มีเออเร่อใดๆ กับ javaScripts เลยค่ะ
ไฟล์ test รันเดี่ยวๆ ปุ่ม diasble ทำงานได้ปกติค่ะ แต่พอมารวมกับ reLoad มันกลับไม่ทำงานอะคะ
รบกวนด้วยนะคะ
ขอโทษที่ตั้งกระทู้ซ้ำซ้อนค่ะ!
|
 |
 |
 |
 |
Date :
2010-10-14 21:52:34 |
By :
mzchewiize |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แก้ได้แล้วค่ะ ขอบคุณพื้นที่ thaicreate ค่ะ
|
 |
 |
 |
 |
Date :
2010-10-14 23:26:03 |
By :
mzchewiize |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|