This article mainly introduces the example of asynchronous deletion using js in Yii2.0. The editor thinks it is quite good, so I will share it with you now and give it as a reference. Let’s follow the editor to take a look.
Organize the documents, search out an example of using js asynchronous deletion in Yii2.0, and organize and streamline it a little for sharing.
Controller:
public function actionWeixinnotificationdel() { $model = WxDistributorNotification::findOne($_GET['id']); if ($model) { if($model->delete()) { echo 1; Yii::$app->end(); } } echo 0; Yii::$app->end(); }
ViewHTML
Copy code The code is as follows:
<a href="javascript:void(0);" rel="external nofollow" url="<?=Url::to(['weixinnotificationdel', 'id'=>$model->id]);?>" class="btn btn-success btn-sm deleteLink">解绑</a>
ViewJS
<script language="Javascript"> $(function () { $('.deleteLink').click(function () { var tThis =$(this); if (confirm("确定要解绑此微信号吗?")){ var url = tThis.attr('url'); $.get(url,function (data) { if (data == 1){ $(tThis).parent().parent().remove() alert('解绑成功') }else{ alert('解绑失败') } }) } return false; }) }) </script>
The above is the detailed content of js asynchronous deletion sample code used in Yii2.0. For more information, please follow other related articles on the PHP Chinese website!