|
 |
|
ขอคำแนะนำ Query กับ Ajax มีรูปตัวอย่าง รบกวนด้วยค่ะ |
|
 |
|
|
 |
 |
|
ขนาดเกิน หรือ จำนวนเกินคับ
ไปนอนแระ
|
 |
 |
 |
 |
Date :
2010-09-01 02:01:40 |
By :
pjgunner |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองเอาโค้ดที่เขียนมาดูนะคะ
วิธีการคร่าว ๆ ของ ajax ก็คือ request และ response ค่ะ กระบวนการก็คือ มันจะทำการ request ไปยัง query หรือ file php ที่คุณระบุำไว้
จากนั้นก็รอรับ response ที่ query หรือ file php ตอบกลับมา response มาจากไหน? ก็มาจากค่าที่คุณ print / echo / แสดง ออกมาใน file php นั้นแหละค่ะ
|
 |
 |
 |
 |
Date :
2010-09-01 09:26:07 |
By :
ultrasiam |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ค่ะ อันนี้เป็นส่วน Script
<script language="JavaScript">
var HttPRequest = false;
function check() {
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 = 'preupload_check.php';
var pmeters = "tUsername=" + encodeURI( document.getElementById("filename").value);
document.getElementById('upload').disabled = true; << จริงๆตรงนี้มันต้องเชคตามเงื่อนไขอะคะ อันนี้มัน Disable อย่างเดียวเลย
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("mySpan1").innerHTML = "..";
}
if(HttPRequest.readyState == 4) // Return Request
{
if(HttPRequest.responseText == 'Y')
{
window.location = 'AjaxPHPRegister3.php';
}
else
{
document.getElementById("mySpan1").innerHTML = HttPRequest.responseText;
}
}
}
}
</script>
อันนี้เป็นส่วนที่ตรวจสอบอะคะ
<?
$strUsername = trim($_POST["tUsername"]);
@session_start();
@$_SESSION['username']="$username";
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("sigdb");
$strSQL = "SELECT servname,Filename FROM preupload
WHERE servname ='$username'and Filename like '%".$strUsername."%'";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$objResult = mysql_num_rows($objQuery);
if(mysql_num_rows($objQuery)== 3)
{
echo" Error"; /// ถ้าขึ้น Error ปุ่ม ทำการอัพโหลดจะ Disable
}
else
{
echo" OK";
}
mysql_close($objConnect);
?>
คิดว่าต้องแก้ตรงส่วนของ script แต่ไม่ทราบว่าจะส่งค่าอย่างไรคะ รบกวนขอคำแนะนำจากทุกท่านด้วยค่ะ
|
ประวัติการแก้ไข 2010-09-01 09:58:54
 |
 |
 |
 |
Date :
2010-09-01 09:56:11 |
By :
mzchewiize |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตัวนี้ไงคะ --> HttPRequest.responseText
|
 |
 |
 |
 |
Date :
2010-09-01 16:17:15 |
By :
ultrasiam |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช่ค่ะ
ให้เช็คใน if(HttPRequest.readyState == 4) // Return Request นะคะ
|
 |
 |
 |
 |
Date :
2010-09-01 16:57:25 |
By :
ultrasiam |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|