前端部分
<style>
.overlay{
background:transparent url(images/overlay.png) repeat top left;
position:fixed;
top:0px;
bottom:0px;
left:0px;
right:0px;
z-index:100;
}
.box{
position:fixed;
background:rgba(0,0,0,0.8);
color:#fff; height:30px;
margin-top:-15px;
top:-100%;
left:50%;
width:100%; text-align:center; line-height:30px;
margin-left:-130px;
-moz-border-radius: 5px;
-webkit-border-radius:5px;
-khtml-border-radius:5px;
z-index:101;
}
</style>
<div class="overlay" id="overlay" style="display:none;"></div>
<div class="box" id="box" style="width:250px;z-index:99999999">恭喜您提交成功,您已获得{$question.joined_points}积分</div>
<script>
function tishi(){
$('#overlay').fadeIn('fast', function () {
$('#box').animate({ 'top': '50%' }, 500);
$("#mess").html();
setTimeout("tishiclose()",2000);//2秒消失,可以改动
});
}
function tishiclose(){
$('#box').animate({ 'top': '-100%' }, 500, function () {
$('#overlay').fadeOut('fast');
});
}
//跳转地址
function skip(){
location.href="{:U('Survey/detail')}";
}
$('#sub').click(function(){
var xuan=document.getElementsByName("xuanx");//不能getElementById,ById又只会读数组第一个值
var xuanxid;
for(var i = 0; i < xuan.length; i++)
{
if(xuan[i].checked)
xuanid=xuan[i].value;
}
var url="__URL__/get_answer";
var postdata = "xuanx="+xuanid;
$.post(url,postdata,function(data){
if(data.c == 1){
$('#overlay').fadeIn('fast', function () {
$('#box').animate({ 'top': '50%' }, 500);
//$("#mess").html();
setTimeout("tishiclose()",2000);//2秒消失,可以改动
});
setInterval("skip()", 2000);
}else{
alert(data.m);
return false;
}
})
})
</script>
后端php部分
//ajax提交用户选择问题的答案
public function get_answer(){
$userid = I('session.uid');
$xuanx = I('request.xuanx',"");
$question_id =1;
$user_question = M('WenjuanAnsinfo')->where(array('user_id'=>$userid,'question_id'=>$question_id))->select();
if(!$user_question){
$data = array(
'question_id'=>1,
'user_id'=>$userid,
'ans_id'=>$xuanx,
'ans_date'=>time(),
);
$add = M('WenjuanAnsinfo')->add($data);
$wenjuan_point = M('WenjuanQuestion')->where(array('question_id'=>$question_id))->find();
//赠送积分
$getPoints = M('UserPoint')->where(array('user_id'=>$userid))->setInc('points',$wenjuan_point['joined_points']);
$joined_count = M('WenjuanAnsinfo')->where(array('question_id'=>1))->count();
M('WenjuanQuestion')->where(array('question_id'=>1))->save(array('joined_count'=>$joined_count));
if($add && $getPoints){
set_return_value('成功', 1, null);
}else{
set_return_value('提交问卷调查失败', 0, null);
}
}
}