jquery ajax 應用執行個體<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>jquery ajax 應用執行個體</title>
<script language="網頁特效">
$(document).ready(function(){
var a={};$(".followpreview").mouseo教程ver(function(){
var h=$(this);var b=h.attr("id"),d=h.offset().left,j=h.offset().top+h.height(),g="";var e=$("body").width();
if(e-d<210){d=d-186;g="followerpreviewboxarrright"}else{g="followerpreviewboxarrleft";}
a[b]=window.settimeout(function(){
var l="box"+b;var k=b.replace("fu","");
if(document.getelementbyid(l)==null){
$("body").append('<div class="followerpreviewbox" id="'+l+'"></div>');
$("#"+l).css教程({left:d,top:j}).fadein(500);
$.ajax({type: "get",url: webaddr+"/www.111cn.net/ajax.php教程?act=getuserinfo&uid="+k+"&class="+g+"&rank="+getrandomnum(1,999999),success: function(msg){$("#"+l).html(msg).css("backgroundimage","none");}});
}else{$("#"+l).fadein(500)}},500);function c(){var l=$(this).attr("id");window.cleartimeout(a[l]);var k="box"+l;$("#"+k).fadeout(500)}}
).mouseout(function(){var c=$(this).attr("id");window.cleartimeout(a[c]);var b="box"+c;$("#"+b).hide()})});
</script>
</head>
<body>
ajax.php 檔案
<?php
$api=1;
include('../common.inc.php');
//發送私信
if($action=='send') {
$content = trim($_post["content"]);
$funame = $_post["funame"];
$user=user_info("user_name='$funame'");
if (!$user['user_id']) {
echo '您發送的使用者不存在';
exit;
}
if (!empty($content)) {
$content=getsubstrutf8($content,0,140,false);
$content=replace($content);
$content=daddslashes($content);
$db->query("update et_users set priread = priread+1 where user_id='$user[user_id]'");
$db->query("insert into et_messages (senduid,sendname,sendnickname,sendhead,sendtouid,sendtoname,sendtonickname,messagebody,sendtime) values ('$my[user_id]','$my[user_name]','$my[nickname]','$my[user_head]','$user[user_id]','$user[user_name]','$user[nickname]','$content','$addtime')");
echo 'success';
exit;
} else {
echo '您沒有填寫發送的內容,返回重新填寫';
exit;
}
}
if ($act=='getuserinfo') {
$uid=$_get['uid'];
$class=$_get['class'];
$userquery = $db->query("select nickname,user_head,lastcontent,lastconttime from et_users where user_id='$uid'");
$user=$db->fetch_array($userquery);
$head=$user['user_head']?"$webaddr/attachments/head/".$user['user_head']:"$webaddr/images/noavatar.jpg";
$content=simplecontent($user[lastcontent]);
$time=$user[lastconttime]?timeop($user[lastconttime]):"";
echo '<div class="'.$class.'"></div><table width="200" border="0" cellpadding="0" cellspacing="0"><tr><td width="53" rowspan="2" align="left" valign="top"><img src="'.$head.'" width="48px" /></td><td><strong>'.$user[nickname].':</strong>'.emotionrp($content).'</td></tr><tr><td class="followtime">'.$time."</td></tr></table>";
exit;
}
if ($act=='getreplycontent') {
$contid=$_get['contid'];
$contdata=getreply($contid);
if ($contdata) {
$contents=ubb($contdata['content_body']);
echo '<div class="status_reply_list">
<div class="top"></div>
<div class="cont">
<h1 class="line">以下是原文:<a href="'.$webaddr.'/op/view/'.$contid.'">原文回複('.$contdata['replytimes'].')</a></h1>
<div class="replyajaxbox"><a href="'.$webaddr.'/'.$contdata['user_name'].'">'.$contdata['user_nickname'].'</a>:'.$contents.'</div>
</div>
<div class="bottom"></div>
</div>';
}
}
?>
</body>
</html>