|
 |
|
ใช้ ajax เรียกอีกไฟล์กลับมาแสดงผลในแท็ก div แต่ jquery ไม่ทำงาน ทำอย่างไรดีครับ |
|
 |
|
|
 |
 |
|
ผมต้องการให้ user หรือ admin ล็อกอินเข้ามาแล้วแสดงผลต่างกันอ่ะครับ แต่ไม่อยากสั่งรีเฟรชทั้งหน้า
เลยใช้ ajax ไปตรวจสอบอีกหน้าหนึ่งว่าเจอคุกกี้แอดมินให้แสดงอย่างงี้ เจอคุกกี้ยูสเซอร์ให้แสดงอย่างงั้น
แต่พอสั่งมาโชว์ในแท็ก div jquery กลับไม่ทำงานครับ มีวิธีอย่างไรให้แสดงผลในแท็ก div แล้ว jquery ทำงานครับ
หรือมีวิธียังไงครับว่า ถ้ากดล็อกอินเข้ามา แล้วจะใช้อะไรไปตรวจสอบคุกกี้ ว่าเป็นของใคร แล้วรับคำสั่งกลับมาโชว์แท็กนั้น
แท็กนี้ อะไรประมาณนี้ หรือมีวิธีอื่นยังไงให้ล็อกอินแล้วแบ่งระหว่าง admin กับ user โดยที่ไม่ต้องรีเฟรชทั้งหน้าแล้ว jquery
ทำงาน ช่วยแนะนำหน่อยครับ
ขอบคุณครับ
โค้ดประมาณนี้ครับ
หน้าหลัก
Code (PHP)
<html>
<head>
<script type="text/javascript" src="js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="js/mbMenu.js"></script>
<link rel="stylesheet" type="text/css" href="css/menu.css" media="screen" />
jQuery(function(){
jQuery(".myMenu").buildMenu(
{
template:"menuVoices.html",
additionalData:"pippo=1",
menuWidth:200,
openOnRight:false,
menuSelector: ".menuContainer",
iconPath:"images/",
hasImages:true,
fadeInTime:100,
fadeOutTime:300,
adjustLeft:2,
minZindex:"auto",
adjustTop:10,
opacity:.95,
shadow:false,
shadowColor:"#ccc",
hoverIntent:0,
openOnClick:true,
closeOnMouseOut:false,
closeAfter:1000,
submenuHoverIntent:200
});
jQuery(".vertMenu").buildMenu(
{
template:"menuVoices.html",
menuWidth:170,
openOnRight:true,
menuSelector: ".menuContainer",
iconPath:"ico/",
hasImages:true,
fadeInTime:200,
fadeOutTime:200,
adjustLeft:0,
adjustTop:0,
opacity:.95,
openOnClick:false,
minZindex:200,
shadow:false,
hoverIntent:300,
submenuHoverIntent:300,
closeOnMouseOut:true
});
jQuery(document).buildContextualMenu(
{
template:"menuVoices.html",
menuWidth:200,
overflow:2,
menuSelector: ".menuContainer",
iconPath:"ico/",
hasImages:false,
fadeInTime:100,
fadeOutTime:100,
adjustLeft:0,
adjustTop:0,
opacity:.99,
closeOnMouseOut:false,
onContextualMenu:function(o,e){}, //params: o = the contextual menu,e = the event
shadow:false
});
});
function check_admin2(){
var req;
if(window.XMLHttpRequest)
{
req = new XMLHttpRequest();
}
else if(window.ActiveXobject)
{
req = new ActiveXObject("Mocrosoft.XMLHTTP");
}
else
{alert('Browser not support');
return false;
}
var str=Math.random();
var querystr="admin.php?pop="+str;
req.open("GET",querystr,true);
req.send(null);
req.onreadystatechange=function(){
if(req.readyState==4){document.getElementById('admin').innerHTML=req.responseText;}
}
}
</head>
<body>
<div id="admin"></div>
</body>
</html>
Code (PHP)
หน้า admin.php (หน้าที่ถูกเรียก)
<?
header("content-type: text/html; charset=windows-874");
if(isset($_COOKIE['admin'])){
echo "admin"; //อันนี้สมุติว่าแอดมินล็อกอินเข้ามานะครับ
}else{?>
<table width="50%" border="0" cellpadding="0" cellspacing="0" bgcolor="#84b1d9"align="right">
<tr>
<td class="myMenu">
<table class="rootVoices" cellspacing='0' cellpadding='0' border='0'><tr>
<a href="/index.html" > <td class="rootVoice {menu: 'menu_1'}" >หน้าแรก</td></a>
<td class="rootVoice {menu: 'menu_2'}" >มุมสมาชิก</td>
<td class="rootVoice {menu: 'menu_3'}" >แพคเกจทัวร์</td>
<td class="rootVoice {menu: 'menu_4'}" >วิธีชำระเงิน</td>
<td class="rootVoice {menu: 'menu_5'}" >webboard</td>
</tr></table>
</td>
</tr>
</table>
<div id="menu_2" class="mbmenu">
<? if($_COOKIE['user']==""){?> <a href="/register.html" class="{img: 'register.png'}" >สมัครสมาชิก</a><? }?>
<a href="/forget.html" class="{img: 'forgot.jpg'}" >ลืมรหัสผ่าน</a>
<a href="/register.html"class="{img:'edit.gif'}">แก้ไขข้อมูลส่วนตัว</a>
</div>
<div id="menu_3" class="mbmenu">
<a href="/package.html" class="{img: 'package.jpg'}" >แพคเกจ</a>
</div>
<div id="menu_4" class="mbmenu">
<a href="/payment.html" class="{img: 'pay.bmp'}" >วิธีชำระเงิน</a>
<a href="/order_view.html" class="{img: 'payment.bmp'}" >แจ้งการชำระเงิน</a>
<a href="/chk_pay.html" class="{img: 'pay_confirm.jpg'}" >ตรวจสอบการชำระเงิน</a>
</div>
<div id="menu_5" class="mbmenu">
<a href="/webboard.html" class="{img: 'webboard.bmp'}" >เว็บบอร์ด</a>
</div><? }
?>
คือโค้ดไม่มีปัญหาไรหรอกครับ แต่เอามาโชว์ในแท็ก <div id="admin"></div> jquery มันจะไม่ทำงานครับ แต่ถ้าโค้ดพวกนี้มันอยู่หน้าเดียวกันมันก็ทำงานครับ
Tag : PHP, MySQL, Ajax, jQuery

|
ประวัติการแก้ไข 2011-04-09 17:09:43 2011-04-09 17:30:50
|
 |
 |
 |
 |
Date :
2011-04-09 16:55:50 |
By :
เด็กโง่ |
View :
2930 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
|
|

|
Load balance : Server 02
|