精准传达 · 有效沟通
创造有活力的品牌网站 提升用户体验和品牌价值感

ajax获取html标签里自定义的数据无刷新提交

来源:未知 admin | 2019-04-13

  $(document).ready(function(){
 
  $(".toupiao.tpspan").click(function(){
 
   varl=$(this).attr("data-l");//获取html标签里的的值,有时候比较方便<span data-l='1' data-g='2'>
 
   varg=$(this).attr("data-g");
 
   vardata={'data[leixing]':l,'data[guzhi]':g};//POST ajax提交 值
 
   varmythis=$(this);
 
   $.ajax({
 
   type:"POST",
 
   url:"/index.php?c=form&a=ajaxpost&modelid=19",
 
   data:data,
 
   dataType:'json',
 
   success:function(mymsg){
 
   if(mymsg['code']==22){
 
   layer.msg(mymsg['msg'],{icon:5,time:2000,anim:6,shade:[0.5,'#393D49']});
 
   setTimeout(function(){
 
   location.href=mymsg['url'];
 
   },1000)
 
   returnfalse;
 
   }
 
   if(mymsg['code']==1){
 
   layer.msg('投票成功',{time:500});
 
  
 
   mythis.children('i').html(parseInt(mythis.children('i').html())+1);
 
  
 
   }else{
 
   layer.msg(mymsg['msg'],{icon:5,anim:5,time:1000,shade:[0.5,'#393D49']});
 
   returnfalse;
 
   }
 
   }
 
   });
 
  });