|
 |
|
รบกวนขอโค๊ดปุ่มค้นหาให้ข้อมูลแสดงในหน้าเดียวกันหน่อยค่ะ |
|
 |
|
|
 |
 |
|
เอาแบบ Refrash หน้าจอ หรือไม่ Refrash ครับ
ถ้าแบบไม่ Ref หน้าจอ ก็ใช้ Ajax หรือ jquery
ถ้าแบบ Ref หน้าจอ ก็ใช้ php ธรรมดา
|
 |
 |
 |
 |
Date :
2010-12-09 08:56:03 |
By :
somparn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แบบไม่ Refrash ค่ะ ขอดูตัวอย่างโค๊ดได้มั้ยค่ะ ไม่ค่อยเข้าใจค่ะ
|
 |
 |
 |
 |
Date :
2010-12-09 09:01:48 |
By :
fufu |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<form>
<p>Username : <input type="text" id="user" name="user" /><span id="result"> </span></p>
<p>ลองพิมพ์คำว่า demo,thaicreate,phpbasic ลงในช่อง Username (ทีละตัว)</p>
<p>Email : <input type="text" id="email" name="email" /></p>
<p>Display Name : <input type="text" id="displayname" name="displayname" /></p>
</form>
<script type="text/javascript">
var doKeyUp = function(event){
var input = GEvent.element(event);
var result = $E('result');
result.innerHTML = '<img src="image/loadding.gif" alt="" />';
var req = new GAjax();
req.send('show.php' , 'user=' + encodeURIComponent(input.value) , function(xhr) {
result.innerHTML = ' ';
var datas = xhr.responseText.toJSON();
var prop, val;
for (prop in datas[0]) {
val = datas[0][prop];
$E(prop).value = val;
};
});
}
$G('user').addEvent('keyup', doKeyUp);
</script>
show.php
Code (PHP)
<?php
header("content-type: text/html; charset=UTF-8");
$users = array('demo', 'thaicreate','phpbasic');
$emails = array('[email protected]', '[email protected]');
$displaynames = array('thaicreate', 'phpbasic!');
$user = trim($_POST['user']);
$i = 0;
while($i < count($users)){
if($users[$i] == $user){
break;
}
$i++;
}
$ret[] = 'email":"'.$emails[$i];
$ret[] = 'displayname":"'.$displaynames[$i];
echo '[{"'.implode('","', $ret).'"}]';
?>
|
 |
 |
 |
 |
Date :
2010-12-09 09:17:11 |
By :
somparn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|