|
 |
|
สอบถามเรื่อง Ajax หน่อยค่ะ ดูใน Ajax ใน tutor แล้วจับจุดไม่ได้อิอิ |
|
 |
|
|
 |
 |
|
<input type=text name=code size=15><input type=buttom value=Check>
|
 |
 |
 |
 |
Date :
2009-10-26 16:04:48 |
By :
nilas |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
งง คือไรเหรอคะพี่ lashi
|
 |
 |
 |
 |
Date :
2009-10-26 16:31:21 |
By :
gigza |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
โค้ดตรวจสอบ ajax จะยาวหน่อยน่ะครับ ถ้าใช้ jquery หรือ framework อื่นๆจะช่วยลดโค้ดส่วนนี้ไป
Ajax code
<script>
function fncCheck(){
var param ="code="+document.getElementById('code').value;
var xmlHttp =GetXmlHttpObject();
if(xmlHttp== null){
alert("your browser does not support ");
return;
}
xmlHttp.onreadystatechange = function(){
if(xmlHttp.readyState ==4 && xmlHttp.status==200){
var val =xmlHttp.responseText;
if(val ==0) alert("ไม่มีค่านี้ในฐานข้อมูล");
else document.getElementById('showCode').innerHTML=val;
}
}
xmlHttp.open("GET","check.php?"+param,true);
xmlHttp.send(null);
}
function GetXmlHttpObject(){
var xmlHttp =null;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
xmlHttp = new XMLHttpRequest();
if (xmlHttp.overrideMimeType) {
xmlHttp.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
return xmlHttp;
}
</script>
<input type="text" id="code" size=15>
<input type="button" value="Check" onclick="javascript:fncCheck()">
<div id="showCode"></div>
check.php(PHP)
<?php
//This is code test
// echo "TEST GET HTTP :".$_GET[code];
include ("directory config connect");
$code = $_GET[code];
$sql =mysql_query("select * from tbl_name where field_name=$code") or die(mysql_error());
$res= mysql_fetch_array($sql);
$num = mysql_num_rows($sql);
if($num>0){
echo $res[field_name];
}else{
echo 0;
}
?>
|
 |
 |
 |
 |
Date :
2009-10-26 16:41:43 |
By :
xbeginner01 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณค่ะพี่
|
 |
 |
 |
 |
Date :
2009-10-26 20:37:56 |
By :
gigza |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
หายไปนานเลยนะครับน้องเอ๋ คิดถึงๆๆๆๆ
|
 |
 |
 |
 |
Date :
2009-10-26 23:56:12 |
By :
somparn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|