ajax - how to include js file using asset on yii2 advanced template -
i have folowoed following guide http://www.yiiplayground.com/yii2/web/index.php?r=ajax/index how can include js file using assets. following file have created under /frontend/assets
<?php namespace frontend\assets; use yii\web\assetbundle; class ajaxasset extends assetbundle{ public $basepath = '@frontend'; public $baseurl = '/view'; public $css = [ ]; public $js = [ 'ajax/ajax.js', ]; public $depends = [ 'yii\web\yiiasset', 'yii\bootstrap\bootstrapasset', ]; } ?>
i have managed make work updating following
//public $basepath = '@webroot'; //public $baseurl = '@web'; public $sourcepath = '@frontend/views/ajax';
however having problem javascript file.
views/ajax/ajax.js
'reportsviewdone': function (response) { // called link attribute 'data-on-done' => 'simpledone' console.dir(response); $('#css3buttons').html(response.body); }
i syntax error
syntaxerror: missing ; before statement 'reportsviewdone': function (response) {
i have fixed changing
var ajaxcallbacks = { 'reportsviewdone': function (response) { // called link attribute 'data-on-done' => 'simpledone' console.dir(response); $('#css3buttons').html(response.body); } }
do need separate asset this? if not, make use of work advanced template had done (they wouldn't call template nothing), use site-wide appasset.php. put
public $js = [ 'js/ajax.js', ];
there , put ajax.js frontend/web/js
i'm quite positive views
isn't best place js files.
before making changes $basepath
, $baseurl
, make sure you're using them properly, aliases.
Comments
Post a Comment