本文介绍了在yii2中通过ajax显示kartik咆哮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用kartik咆哮,我想通过ajax成功展示咆哮

Am using kartik growl and i would like to show the growl via ajax success

我尝试过

这是 javascript 代码:

$.post({
  url: "forwardpr", // your controller action
  dataType: 'json',
  data: {keylist: keys,user:userdata},
  success: function(data) {
      console.log(data);
    //$.pjax.reload({container:'#forward-grid'});
    $.growl( data.growl );
  },
  error: function(err){
  alert(err);
  console.log("server error");
  }
});

这是控制器代码:

$growl = [
  'title' => "Group members updated.<hr>",
  'icon' => 'glyphicon glyphicon-ok-sign',
  'message' => "Successifully updated.",
  'showSeparator' => true,
];

echo json_encode(['response'=>"Successifully forwarded pr(s)", 'growl' => $growl ]);

推荐答案

如果看到TypeError: $.growl is not a function,则表明您没有在 AppAsset.php 文件中包含必需的文件.

If you see TypeError: $.growl is not a function, then it means you have not included required files to AppAsset.php file.

要解决此问题,请转到 assets/AppAsset.php 文件并添加:

To solve this problem, go to assets/AppAsset.php file and add:

public $css = [
        // ... Something else might be here
        'css/jquery.growl.css',
    ];

还有

public $js = [
        // Something else might be here
        'js/core.js',
    ];

由于缺少.js文件,因此控制台(TypeError: $.growl is not a function)中存在该错误.但是,您还必须添加.css文件,因为如果没有该文件,即使它可以工作,您也不会看到咆哮声.

Because of missing .js file, you have that error in console (TypeError: $.growl is not a function). But you also must add .css file as well because without it you will not see growl, even though it works.

这篇关于在yii2中通过ajax显示kartik咆哮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 12:09