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>