Example of asynchronous deletion using js in Yii2.0 and yii2.0js
Sort out the document, search for an example of using js asynchronous deletion in Yii2.0, and streamline it 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();}
View HTML
Copy codeThe Code is as follows:
<A href = "javascript: void (0);" rel = "external nofollow" url = "<? = Url: to (['weixinnotifdel ', 'id' => $ model-> id]);?> "Class =" btn-success btn-sm deleteLink "> unbind </a>
View JS
<Script language = "Javascript"> $ (function () {$ ('. deleteLink '). click (function () {var tThis = $ (this); if (confirm ("are you sure you want to unbind this number? ") {Var url = tThis. attr ('url'); $. get (url, function (data) {if (data = 1) {$ (tThis ). parent (). parent (). remove () alert ('unbinding successfully')} else {alert ('unbinding failed') }}return false ;}) </script>
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.