一个关于简单留言板的问题 写了个简易留言板,提交留言后,页面就会转向做后台处理的php页面,因为提交后页面跳转到php页面后就一片白了,不雅观。如何使他停留在当前页面?求指点 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你在后台处理的php页面最后再转向回到原页面即可。 1.直接提交到本页处理2.传到处理页的时候加一个参数表明跳回到哪里,处理完跳回3.ajax 不用本页处理就必须得用AJAX请求!达到无刷新提交留言! 我来回答。几种方法。1.直接提交到本页处理2.提交到其他页面处理,处理完后再返回。要想实现局部刷新效果。1.ajax 复杂些2.嵌入iframe直接提交到本页处理我有完整的php源码,我只列出php代码,参考下。<?phpfunction ToHtml($text){ $text=htmlspecialchars($text); $text=trim($text); $text=str_replace("\r","",$text); $text=str_replace("\n","<br/>",$text); $text=str_replace(" "," ",$text); return $text;}?><?php$action=$_REQUEST[action];$page=$_REQUEST[curPage];$check1=$_REQUEST[check1];$name=$_REQUEST[name];$content=$_REQUEST[content];$ip=$_SERVER["REMOTE_ADDR"];if(empty($page)){ $page=1;}if (!empty($check1)){ $name="匿名网友";}if (empty($content)){ $action="list";}else if(empty($name)){ $action="list";}else{ $action="submit";}if($action=="submit"){ $conn=mysql_connect("localhost","root","root")or die("error:".mysql_error()); mysql_select_db("udb_name"); mysql_query("set names gb2312"); $sql="insert into bbs(gst_user,gst_content,gst_ip) values('".$name."','".$content."','".$ip."')"; mysql_query($sql);}$action="list";$conn=mysql_connect("localhost","root","root")or die("error:".mysql_error());mysql_select_db("udb_name");mysql_query("set names gb2312");$pagesize=10;$sql="select * from bbs order by gst_time desc";$_result=mysql_query($sql);$total=mysql_num_rows($_result);$pageCount=1+(int)(($total-1)/$pagesize);$result=mysql_query($sql." limit ".$pagesize*($page-1).",".$pagesize,$conn);?><div style="font-family:微软雅黑;width: 810px;height: 147px;text-align: left; overflow: visible; background-color: white;" id="bbs"> <span style="font-size: 11pt"><strong>首页>留言板<br/></strong></span><form action="index.php" method="post"><textarea name="content" style="width: 800px; height: 69px; overflow: auto;"></textarea><br/><input id="Submit1" type="submit" value="留言" style="width: 51px; color: white; background-color: #ff8901" /> <input id="check1" name="check1" type="checkbox" value="on" />匿名 你的姓名<input id="name" name="name" style="left: 7px; width: 110px;position: relative; top: 2px" type="text" /></form><?phpif($pageCount==1){?>首页 上一页 下一页 尾页<?php}else if($page<=1){?>首页 上一页 <a href=<?php echo $curUrl."?action=".$action."&curPage=".($page+1);?>>下一页</a> <a href=<?php echo $curUrl."?action=".$action."&curPage=".$pageCount;?>>尾页</a><?php}else if($page>=$pageCount){?><a href=<?php echo $curUrl."?action=".$action."&curPage=1";?>>首页</a> <a href=<?php echo $curUrl."?action=".$action."&curPage=".($page-1);?>>上一页</a> 下一页 尾页<?php}else{?><a href=<?php echo $curUrl."?action=".$action."&curPage=1";?>>首页</a> <a href=<?php echo $curUrl."?action=".$action."&curPage=".($page-1);?>>上一页</a> <a href=<?php echo $curUrl."?action=".$action."&curPage=".($page+1);?>>下一页</a> <a href=<?php echo $curUrl."?action=".$action."&curPage=".$pageCount;?>>尾页</a><?php}echo " ".$page."/".$pageCount;while ($info=mysql_fetch_row($result)){ echo "<hr color=gray size=1>"; echo "<span style=color:gray;font-size:14px>".ToHtml($info[1])." ".ToHtml($info[3])." ".ToHtml($info[4])."</span><br/>"; echo "<span style=color:black;font-size:16px>".ToHtml($info[2])."</span>";}echo "</div>";?> 把表建好可是可以直接用的啊。表bbs的内容为 id username content ip time. 如何用html字符串创建jquery对象? ajax问题,怎么实现上一页,下一页? 那个“一晚上的游戏”我也做一个版本。分享一下。 json数据到ext前台显示的问题 网易新闻评论效果是扎回事? 求指导google 地图API 显示多个图标和信息框问题,急急急,在线等 javascript粗潜问题 求助:关于字符串替换的问题 为什么不能改变table的bordercolor??详情请进--〉 在JAVASCRIPT中,怎样取得两个数相除的整数部分??? 下面代码为什么点确认和取消都保存文件?请各位帮我把把脉! 不唐突的javascript事件绑定问题
2.传到处理页的时候加一个参数表明跳回到哪里,处理完跳回
3.ajax
1.直接提交到本页处理
2.提交到其他页面处理,处理完后再返回。
要想实现局部刷新效果。
1.ajax 复杂些
2.嵌入iframe直接提交到本页处理我有完整的php源码,我只列出php代码,参考下。<?php
function ToHtml($text)
{
$text=htmlspecialchars($text);
$text=trim($text);
$text=str_replace("\r","",$text);
$text=str_replace("\n","<br/>",$text);
$text=str_replace(" "," ",$text);
return $text;
}
?>
<?php
$action=$_REQUEST[action];
$page=$_REQUEST[curPage];
$check1=$_REQUEST[check1];
$name=$_REQUEST[name];
$content=$_REQUEST[content];
$ip=$_SERVER["REMOTE_ADDR"];if(empty($page))
{
$page=1;
}
if (!empty($check1))
{
$name="匿名网友";
}
if (empty($content))
{
$action="list";
}
else if(empty($name))
{
$action="list";
}
else
{
$action="submit";
}
if($action=="submit")
{
$conn=mysql_connect("localhost","root","root")or die("error:".mysql_error());
mysql_select_db("udb_name");
mysql_query("set names gb2312");
$sql="insert into bbs(gst_user,gst_content,gst_ip) values('".$name."','".$content."','".$ip."')";
mysql_query($sql);
}
$action="list";
$conn=mysql_connect("localhost","root","root")or die("error:".mysql_error());
mysql_select_db("udb_name");
mysql_query("set names gb2312");
$pagesize=10;
$sql="select * from bbs order by gst_time desc";
$_result=mysql_query($sql);
$total=mysql_num_rows($_result);
$pageCount=1+(int)(($total-1)/$pagesize);
$result=mysql_query($sql." limit ".$pagesize*($page-1).",".$pagesize,$conn);
?>
<div style="font-family:微软雅黑;width: 810px;height: 147px;text-align: left; overflow: visible; background-color: white;" id="bbs">
<span style="font-size: 11pt"><strong>首页>留言板<br/>
</strong></span>
<form action="index.php" method="post">
<textarea name="content" style="width: 800px; height: 69px; overflow: auto;"></textarea><br/>
<input id="Submit1" type="submit" value="留言" style="width: 51px; color: white; background-color: #ff8901" />
<input id="check1" name="check1" type="checkbox" value="on" />
匿名
你的姓名<input id="name" name="name" style="left: 7px; width: 110px;position: relative; top: 2px" type="text" />
</form>
<?php
if($pageCount==1)
{?>
首页 上一页 下一页 尾页
<?php
}
else if($page<=1)
{?>
首页 上一页
<a href=<?php echo $curUrl."?action=".$action."&curPage=".($page+1);?>>下一页</a>
<a href=<?php echo $curUrl."?action=".$action."&curPage=".$pageCount;?>>尾页</a>
<?php
}
else if($page>=$pageCount)
{?>
<a href=<?php echo $curUrl."?action=".$action."&curPage=1";?>>首页</a>
<a href=<?php echo $curUrl."?action=".$action."&curPage=".($page-1);?>>上一页</a>
下一页 尾页
<?php
}
else
{?>
<a href=<?php echo $curUrl."?action=".$action."&curPage=1";?>>首页</a>
<a href=<?php echo $curUrl."?action=".$action."&curPage=".($page-1);?>>上一页</a>
<a href=<?php echo $curUrl."?action=".$action."&curPage=".($page+1);?>>下一页</a>
<a href=<?php echo $curUrl."?action=".$action."&curPage=".$pageCount;?>>尾页</a>
<?php
}
echo " ".$page."/".$pageCount;
while ($info=mysql_fetch_row($result))
{
echo "<hr color=gray size=1>";
echo "<span style=color:gray;font-size:14px>".ToHtml($info[1])." ".ToHtml($info[3])." ".ToHtml($info[4])."</span><br/>";
echo "<span style=color:black;font-size:16px>".ToHtml($info[2])."</span>";
}
echo "</div>";
?>
表bbs的内容为 id username content ip time.