|
 |
|
ขอคำแนะนำเกี่ยวกับ Ajax และการทำงานของ Span ที่มีหลายๆค่าค่ะ |
|
 |
|
|
 |
 |
|
คือ มีหน้า Ajax ตรวจสอบการซ้ำกันของข้อมูล มันตรวจสอบค่าได้ปกติ
คือตั้งเงื่อนไขไว้ว่าถ้ามีไฟล์เท่ากับ 3 ปุ่มอัพโหลดจะ disable ไป
ตอน test หน้านี้ หน้าเดียวคือทำงานได้ปกติ
แต่พอเอาไปรวมกับ AJax อีกหน้ามันกลับไม่ทำงาน มีใครพอจะทราบไหมคะว่า เป็นเพราะอะไร
ลองแก้ชื่อ Span ให้ไม่ซ้ำกันแล้วก็ยังรันไม่ได้อะคะ
อันนี้ส่วนที่ตรวจสอบปุ่ม คือทำงานได้ปกติ ถ้า test แบบเดี่ยวๆ ชื่อไฟล์ test
<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("mySpan").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">
<?
@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">
<tr>
<td><p align="left" class="style2">ไฟล์อ้างอิง
<input type="text" name="filename" id="filename" OnChange="JavaScript:check();"/>
<span id="mySpan"></span></div>
<input name="btnRegister" type="button" id="btnRegister" value="ตรวจสอบ"></input>
<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="ทำการอัพโหลดไฟล์" />
</form></td>
</tr>
</table>
อันนี้อีกอันค่ะ
เป็นส่วนที่เรียกไฟล์ชื่อ test แล้วตรงปุ่ม Disable มันไม่ทำงานอะคะ
<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("mySpan2").innerHTML = "Now is Loading...";
}
if(HttPRequest.readyState == 4) // Return Request
{
document.getElementById('mySpan2').innerHTML = HttPRequest.responseText;
}
}
}
</script>
</head>
<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="mySpan2"></span></td>
</tr>
</table></div>
</body>
</html>
Tag : PHP, Ajax

|
|
 |
 |
 |
 |
Date :
2010-10-14 17:25:09 |
By :
mzchewiize |
View :
1216 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันมี error แจ้งเตือนเกี่ยวกับ JavaScript บ้างหรือเปล่าครับ
|
 |
 |
 |
 |
Date :
2010-10-14 21:36:07 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่มีเออเร่อใดๆเลยค่ะ
คือไฟล์ test รันเดี่ยวๆ มัน disable ปุ่มได้ปกติค่ะ
แต่พอมาีรวมกับ function reLoad มันไม่ทำงานค่ะ
|
 |
 |
 |
 |
Date :
2010-10-14 21:43:39 |
By :
mzchewiize |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แก้ได้แล้วค่ะ ขอบคุณพื้นที่ thaicreate ค่ะ
|
 |
 |
 |
 |
Date :
2010-10-14 23:26:16 |
By :
mzchewiize |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|