ajax 易思内容页弹出,不进入
第一步再模版中加入 传入show(这里是id)
<li><a href="javascript:void(0);" onClick="show([%$array[i].did%]);"><img src="[%$array[i].pic%]" /></a></li>
弹出pop层; 接受参数,改变 可以再footer 模版中
<style>
.pop_wapper{z-index:99; width:100%; height:2000px; background:#000;position: absolute; left:0; top:0;filter:alpha(opacity=60); opacity:0.6; }
.pop{position: absolute; z-index:100;background-color:#f2f2f2; cursor:pointer; width: 1100px;left: 50%; top:100px;
margin-left:-550px;
-webkit-box-shadow: 1px 1px 1px;
-moz-box-shadow: 1px 1px 1px;
box-shadow: 1px 1px 1px;
height:auto;
padding-bottom: 10px;}
.pop_head{position:relative; width:1100px; height:42px; background:#f2f2f2;}
.pop_head a.close{width:42px;height:42px;background:url(../images/fanhui.png);position:absolute;right:10px;line-height:24px;color:#000;text-decoration:none;top:20px;}
.pop_body{background:#f2f2f2;width:950px; min-height:500px;
_height:500px; padding-top:18px; margin:0 auto;}
.pop_title{ font-size:22px; border-bottom:1px solid #000; text-align:center; line-height:45px; font-weight:bold;}
.pop_con{ text-align:left; width:950px; line-height:32px; color:#626060; text-align:left; font-size:14px; font-family:微软雅黑; padding-top:20px;}
</style>
<div id="pop_wapper" class="pop_wapper" style="display:none; height:3999px;"></div>
<div id="pop" class="pop" style="display:none;">
<div class="pop_head"><a class="close" href="javascript:void(0);" onClick="hide(<?php echo $m; ?>)"></a></div>
<div class="pop_body">
<div class="pop_title">title</div>
<div align="center" height="35" style="margin-top:10px;" class="riqi">更新时间: <span>2016-01-04</span></div>
<div class="pop_con">
阿萨撒撒撒撒撒阿萨撒撒撒撒撒阿萨撒撒撒撒撒阿萨撒撒撒撒撒阿萨撒撒撒撒撒阿萨撒撒撒撒撒阿萨撒撒撒撒撒阿萨撒撒撒撒撒阿萨撒撒撒撒撒阿萨撒撒撒撒撒阿萨撒撒撒撒撒阿萨撒撒撒撒撒阿萨撒撒撒撒撒阿萨撒
</div>
</div>
</div>
<script type="text/javascript">
// js的编码没有用到
function HTMLEnCode(str)
{
var s = "";
if (str.length == 0) return "";
s = str.replace(/&/g, ">");
s = s.replace(/ </g, "<");
s = s.replace(/>/g, ">");
s = s.replace(/ /g, " ");
s = s.replace(/\'/g, "'");
s = s.replace(/\"/g, """);
s = s.replace(/\n/g, " <br>");
return s;
}
//js这里是自己做解码,
function HTMLDeCode(str)
{
var s = "";
if (str.length == 0) return "";
s = str.replace(/>/g, ">");
s = s.replace(/</g, " <");
s = s.replace(/>/g, ">");
s = s.replace(/ /g, " ");
s = s.replace(/'/g, "\'");
s = s.replace(/"/g, "\"");
s = s.replace(/ <br>/g, "\n");
return s;
}
function HTMLEncode2 ( input )
{
var converter = document.createElement("DIV");
converter.innerText = input;
var output = converter.innerHTML;
converter = null;
return output;
}
function hide(num){
$(".pop").hide(1000);
$(".pop_wapper").hide(0);
}
function showme(id){
var h = $(document).scrollTop();
$(".pop").show(100);
$(".pop_wapper").show(0);
$(".pop").css('top',h-0+100);
$.ajax({
type:"POST",
url:"[%$url%]datacache/ajax_content.php",
//async:false,
data:"id=" + id,
success:function (result){
ajaxobj=eval("("+result+")");
$(".pop_title").html(HTMLDeCode(ajaxobj.title));
$(".riqi span").html(HTMLDeCode(ajaxobj.addtime));
//alert(ajaxobj.content);
$(".pop_con").html(HTMLDeCode(ajaxobj.content));
}
},"text")
}
</script>
服务器端,示范
根据id 传回内容和标题的json 格式,记住把实体转位标签
目录是在./datacache/ajax_content.php
<?php
include('./public.php');
$id = $_POST['id'];
$con = mysql_connect(db_host,db_user,db_pw);
if (!$con){
die('Could not connect: ' . mysql_error());//连接失败,提示报错!
}
mysql_query('set names utf8')or die('设置默认编码失败');
$db_selected = mysql_select_db(db_name,$con);//选择数据库
$sql = 'select * from esp_document_content where did='.$id;
$result = mysql_query($sql);
$arr = array();
while($rows = mysql_fetch_array($result)){
//$arr['content'] = addslashes($rows['content']);
//echo $arr['content']
//$arr['content'] = my_nl2br(htmlspecialchars($rows['content'])) ;
//$arr['content'] = htmlspecialchars_decode($rows['content']);
$arr['content'] =zhuanyi(htmlspecialchars_decode($rows['content']));
}
mysql_query('set names utf8')or die('设置默认编码失败');
$db_selected = mysql_select_db(db_name,$con);//选择数据库
$sql = 'select * from esp_document where did='.$id;
$result = mysql_query($sql);
while($rows = mysql_fetch_array($result)){
$arr['title'] = $rows['title'];
$arr['addtime'] = date('Y-m-d',$rows['uptime']);
}
header("Content-type: text/html; charset=utf-8");
foreach ( $arr as $key => $value ) {
$arr[$key] = urlencode ( $value );
}
echo urldecode ( json_encode ( $arr ) );
function zhuanyi($s){
$s =str_replace("/&",">",$s);
$s =str_replace("<","<",$s);
$s =str_replace(">",">",$s);
$s =str_replace(" "," ",$s);
$s =str_replace("\'","'",$s);
$s =str_replace("\"",""",$s);
$s =str_replace("\n"," <br>",$s);
return $s;
}
function my_nl2br($s)
{
return str_replace("\n",'<br>',str_replace("\r",'<br>',str_replace("\r\n",'<br>',$s)));
}
function jsonFormat($data, $indent=null){
// 对数组中每个元素递归进行urlencode操作,保护中文字符
array_walk_recursive($data, 'jsonFormatProtect');
// json encode
$data = json_encode($data);
// 将urlencode的内容进行urldecode
$data = urldecode($data);
// 缩进处理
$ret = '';
$pos = 0;
$length = strlen($data);
$indent = isset($indent)? $indent : ' ';
$newline = "\n";
$prevchar = '';
$outofquotes = true;
for($i=0; $i<=$length; $i++){
$char = substr($data, $i, 1);
if($char=='"' && $prevchar!='\\'){
$outofquotes = !$outofquotes;
}elseif(($char=='}' || $char==']') && $outofquotes){
$ret .= $newline;
$pos --;
for($j=0; $j<$pos; $j++){
$ret .= $indent;
}
}
$ret .= $char;
if(($char==',' || $char=='{' || $char=='[') && $outofquotes){
$ret .= $newline;
if($char=='{' || $char=='['){
$pos ++;
}
for($j=0; $j<$pos; $j++){
$ret .= $indent;
}
}
$prevchar = $char;
}
return $ret;
}
?>

浙公网安备 33010602011771号