首页 > 解决方案 > Yii2 无法执行 Ajax

问题描述

我正在尝试在Yii中执行 Ajax 。但是给了我错误:

传递给 getElementById() 的空字符串

下面是我的 AJAX 代码:

 $url1 = Yii::$app->homeUrl;
    $crurl = 'https://'.$_SERVER['SERVER_NAME'].$url1;
      $this->registerJs('$(document).ready(function(){    
        $(".glyphicon.glyphicon-eye-closed").click(function(){
               $.ajax({
                  url: "'.$crurl.'?r=history/move",
                  type: "post",
                  data: {id: this.id},
                  success: function(data){
                            alert(data);
                   }
                 });
        });
});

标签: phpjqueryajaxyii2

解决方案


检查以下选项;

  1. 检查.glyphicon.glyphicon-eye-closed具有 id attr 的类的 html 代码?

  2. 替换this.id$(this).attr('id');


推荐阅读