我已经了解了以下指南http://www.yiiplayground.com/yii2/web/index.php?r=ajax/index如何使用资产包含js文件。我在/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',
];
}
?>
我已设法通过更新到以下
来使其工作//public $basePath = '@webroot';
//public $baseUrl = '@web';
public $sourcePath = '@frontend/views/ajax';
但是我现在遇到了javascript文件的问题。
views / ajax / ajax.js
'reportsviewDone': function (response) {
// This is called by the link attribute 'data-on-done' => 'simpleDone'
console.dir(response);
$('#css3buttons').html(response.body);
}
我收到语法错误
SyntaxError: missing ; before statement
'reportsviewDone': function (response) {
我已将其修改为
var ajaxCallbacks = {
'reportsviewDone': function (response) {
// This is called by the link attribute 'data-on-done' => 'simpleDone'
console.dir(response);
$('#css3buttons').html(response.body);
}
}