php ajax状态更改
程序员文章站
2022-06-09 14:12:34
//表单@if($v['sex']==0) 男 @elseif($v['sex']==1)
//表单
@if($v['sex']==0)
<td class="se" ss="{{$v['sex']}}" id="{{$v['id']}}" >男</td>
@elseif($v['sex']==1)
<td class="se" ss="{{$v['sex']}}" id="{{$v['id']}}" >女</td>
@endif
//jqery
$(document).on("click",".se",function () {
id=$(this).attr("id");
sex= $(this).attr("ss");
str="";
if (sex==0){
str="男"
}else{
str="女"
}
that=$(this);
$.ajax({
url:"jdjg",
type:"post",
datatype:"json",
data:{
id:id,
sex:str
},
success:function (data) { console.log(data);
if (data=="男"){
that.text("男")
that.attr("ss",0)
} else{
that.text("女")
that.attr("ss",1)
}
}
})
})
//控制器
function jdjg(req $req){
$id= $req->post("id");
$sex=$req->post("sex");
// echo json_encode($sex);die;
if ($sex=="男"){
$res=db::table("poker")->where("id",$id)->update(["sex"=>1]);
$sex="女";
echo json_encode($sex);
}else{
$res=db::table("poker")->where("id",$id)->update(["sex"=>0]);
$sex="男";
echo json_encode($sex);
}
上一篇: 茶树菇猪心汤的做法步骤