js asynchronous deletion sample code used in Yii2.0

黄舟
Release: 2023-03-06 14:04:02
Original
1260 people have browsed it

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();
}
Copy after login

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>
Copy after login

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>
Copy after login


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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!