1. HTML code
<td>@if ($project->done_deal==0)<button type="Button" class="btn Btn-danger btn-xs active done"Uid="{{$project->id}}"status="{{$project->done_deal}}"> No </button>@else<button type="Button" class="btn btn-primary btn-xs active done"Uid="{{$project->id}}"status="{{$project->done_deal}}"> is </button>@endif</td>
2. JS Code
$(". Done"). Click (function () {varid=$ ( This). attr ('UID'); varstatus=$ ( This). attr ('Status'); var_this=$ ( This); if(status==1){ varSta=0; }Else{ varSta=1; } varUrl="{{URL ('/admin/fine/done ')}}"; $.ajax ({type:'Get', Url:url+'/'+id+'/'+status, DataType:"JSON", data: {}, Success:function (data) {Console.log (data); if(data== $) {_this.removeclass ('Btn-danger'). AddClass ('btn-primary'). HTML ('is a'); _this.attr ('ID', id); _this.attr ('Status', STA); }Else{_this.removeclass ('btn-primary'). AddClass ('Btn-danger'). HTML ('No'); _this.attr ('UID', id); _this.attr ('Status', STA); } } }); });
3. PHP Code
Publicfunction Done ($id, $status) {$if _done= $status = =1?0:1; Fine::where('ID', $id)->update (['Done_deal'=$if _done]); //Remove Redis if(Redis::exists ('Fine_project'. $id)) {Redis::d El ('Fine_project'. $id); } if($if _done==1){ return $; }Else{ return -; } }
Click on the button to switch the status of the data directly.
Ajax buttons Change data status