|
|
|
การนำ onload ของ ajax มาแสดงผลมันมีปัญหานิดหน่อยไม่ทราบสามารถแก้ไขได้ไหม |
|
|
|
|
|
|
|
เอาโค้ดหน้าแสดงผลกับ ajax มาดูหน่อยครับ
|
|
|
|
|
Date :
2011-07-30 09:31:25 |
By :
Nautilus |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
หน้าแสดงผลครับ
Code (PHP)
<script language="JavaScript">
var HttPRequest = false;
function doCallAjax(Mode) {
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 = 'save_reply.php';
var pmeters = "&tdetail=" + encodeURI( document.getElementById("detail").value) +
"&tuse=" + encodeURI( document.getElementById("use").value ) +
"&temail=" + encodeURI( document.getElementById("email").value ) +
"&tpid=" + encodeURI( document.getElementById("post").value ) +
"&tMode=" + Mode;
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 = "Now is Loading...";
}
if(HttPRequest.readyState == 4) // Return Request
{
document.getElementById("mySpan").innerHTML = HttPRequest.responseText;
document.getElementById("detail").value = '';
document.getElementById("use").value = '';
document.getElementById("email").value = '';
document.getElementById("post").value ='<?=$pid?>';
}
}
}
</script>
</head>
<body>
<table width="1018" height="150" align="center">
<tr>
<td height="17" align="left" valign="middle" background="bg/bg_whrite.jpg" class="a"><img src="bg/doc.png" width="20" height="20" align="absmiddle" /> <a href="register.php">Register</a> <img src="bg/doc.png" width="20" height="20" align="absmiddle" /> <a href="member_login.php">Member Login</a> <img src="bg/doc.png" width="20" height="20" align="absmiddle" /> <a href="forget.php">Forget </a> <a href="forget.php"> </a><img src="bg/home.png" width="20" height="20" border="0" align="absmiddle" /> <a href="webboard.php">กลับสู่หน้าหลัก</a> [ <strong>PHP </strong> (Hypertext Preprocessor), <strong>ASP </strong> (Active Server Pages), <strong>ASP.NET, VB.NET, C# </strong>] </td>
<tr>
<td width="1010" height="125" align="left" valign="baseline" background="bg/bg4.jpg" class="normal"><h2 class="a"><span class="f">Registered ::</span> <span class="c"><? echo" ".mysql_num_rows($sqluser);?> ( user )</span><span class="style2"><span class="style5"><br />
<span class="b style52 style5">Development by webmaster Thaiclubcom point bank </span></span></span><br />
<br />
<img src="bg/PB_rate15_18up.gif" width="115" height="60" /><a href="webboard.php" ></a><br />
<a href="add_post1.php" class="a" ></a><a href="webboard.php"></a><br />
</h2> </td>
</table>
<br />
<?
include "connect.php";
$sql="select * from tb_post where p_id='$pid' ";
$result=mysql_query($sql);
while($rs=mysql_fetch_array($result)){
$title=$rs['p_title'];
$user=$rs['p_use'];
$detail=$rs['p_detail'];
$date=$rs['p_date'];
$read=$rs['p_read'];
$reply=$rs['p_post'];
$sql1="select * from register where r_user='$user' ";
$result1=mysql_query($sql1);
$rs1=mysql_fetch_array($result1);
$photo=$rs1['r_photo'];
}
?>
<div class="answer" style="height:120px">
<div class="answer1" style="height:25px" align="left">เรื่อง <?="$title?"?>
</div>
<table class="answer2" align="center" width="100" height="25%">
<tr>
<td width="10%" height="73" align="left" valign="top"><p>
<?
if($photo=$photo){
echo"<img src='bg/guest.jpg' align='top'>";
}else{
echo"<img src='bg/guest.jpg' align='top'>";
}
?></td>
<td width="90%" align="left" valign="top" class="white"><p><font class="yellow"><? echo "$detail" ?></font>
<p>
<br />
กระทู้ของ
<span class="style1"><? echo"$user" ?> </span> วันที่ <span class="style1"><? echo"$date" ?> </span> จำนวนผู้อ่าน <span class="style1"><? echo"$read" ?> </span> จำนวนผู้ตอบ <span class="style1"><? echo"$reply" ?> </span> <? echo"<img src='bg/icon_face.gif' align='absmiddle' "?></td>
<body Onload="JavaScript:doCallAjax('LIST');">
</table>
</div>
<br />
<br />
<form name="frmMain" id="frmMain">
<div class="bg2"><font class="white">RE.แสดงความคิดเห็น</font></div>
<div class="bg1">
<table height="95"width="464">
<tr>
<td width="94" height="39" align="left"><font class="yellow"> - Comment ** </font></td>
<td width="358" align="left"><textarea name="detail" cols="35" id="detail"></textarea></td>
<tr>
<td height="23" align="left"><font class="yellow">- Username ** </font></td>
<td align="left" ><input name="use" type="text" id="use" size="40" /></td>
<tr>
<td height="23" align="left"><font class="yellow">- Email address **</font></td>
<td align="left"><input name="email" type="text" id="email" size="40" />
<input name="btn" type="button" id="Submit" value="comment" onclick="javascript:doCallAjax('ADD');" />
<span class="b1">
<input name="post" type="hidden" id="post" value="<?=$pid?>" />
</span> </td>
</table>
</div>
<span id="mySpan"></span>
</form>
หน้าบันทึก
Code (PHP)
<?
date_default_timezone_set('asia/Bangkok');
include"connect.php";
$strMode = $_POST["tMode"];
$pid=$_REQUEST['tpid'];
$detail=$_POST['tdetail'];
$use=$_POST['tuse'];
$email=$_POST['temail'];
$date=date("Y-m-d H:i:s");
$sql1="update tb_post set p_post=p_post +1 where p_id='$pid' ";
$result1=mysql_query($sql1);
$sql2="update tb_post set p_status='a',user_post='Guest' where p_id='$pid' ";
$result2=mysql_query($sql2);
////--------------------เก็บรหัสสินค้าเป็นรหัส------------------************
if($strMode == "ADD"){
$sql = "SELECT r_id FROM tb_reply ORDER BY r_id DESC LIMIT 1";
$result = mysql_query($sql);
if(mysql_num_rows($result) > 0)
{
$row = mysql_fetch_array($result);
sscanf($row[0] ,"0%d" , $id);
$id++;
$sql = "INSERT INTO tb_reply VALUES(CONCAT('0',RIGHT(CONCAT('0000' , $id) , 4)),'$detail','$use','$email','$date','$pid')";
}
else
{
$sql = "INSERT INTO tb_reply VALUES('00001','$detail','$use','$email','$date','$pid')";
}
}
mysql_query($sql);
?>
<?
$sqlreply="select * from tb_reply where pid='$pid' order by r_id desc "; // ****** ดึงข้อมูลการ post ขึ้นมาโชว์
$rss=mysql_query($sqlreply);
while($rs1=mysql_fetch_array($rss)){
$detailr=$rs1['r_detail'];
$use1r=$rs1['r_use'];
$date1r=$rs1['r_date'];
?>
<table class="answer3" align="center" style="vertical-align:top" >
<tr>
<td width="10%" height="70" align="left" valign="top"><p>
<?
if($photo=$photo){
echo"<img src='mypic/$photo' align='top'>";
}else{
echo"<img src='bg/guest.jpg' align='top'>";
}
?>
</p></td>
<td width="90%" align="left" valign="top" class="white"><p><font class="yellow"><? echo "$detailr" ?></font> </p>
<p> <br />
กระทู้ของ
<span class="style1"><? echo"$use1r" ?> </span> วันที่ <span class="style1"><? echo"$date1r" ?></span><span class="style1"> </span> <? echo"<img src='bg/icon_face.gif' align='absmiddle' "?></p></td>
</tr>
<? } ?>
</table>
<?
mysql_close();
?>
|
|
|
|
|
Date :
2011-07-30 09:33:56 |
By :
chonburi f.c |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณมากครับผม คุณ Nautilus
|
|
|
|
|
Date :
2011-07-30 15:54:53 |
By :
chonburi f.c |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|