Home  >  Article  >  Backend Development  >  js asynchronous deletion sample code used in Yii2.0

js asynchronous deletion sample code used in Yii2.0

黄舟
黄舟Original
2017-03-10 19:09:361304browse

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([&#39;weixinnotificationdel&#39;, &#39;id&#39;=>$model->id]);?>" 
class="btn btn-success btn-sm deleteLink">解绑</a>

ViewJS

<script language="Javascript">
$(function () {
 $(&#39;.deleteLink&#39;).click(function () {
  var tThis =$(this);
  if (confirm("确定要解绑此微信号吗?")){
   var url = tThis.attr(&#39;url&#39;);
   $.get(url,function (data) {
    if (data == 1){
     $(tThis).parent().parent().remove()
     alert(&#39;解绑成功&#39;)
    }else{
     alert(&#39;解绑失败&#39;)
    }
   })
  }
  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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn