【问题标题】:Laravel include a view with JavaScriptLaravel 包含一个带有 JavaScript 的视图
【发布时间】:2019-07-18 21:13:04
【问题描述】:

我尝试使用以下脚本通过javascript 在我的页面中包含views

<script>$('#b').append(
        <?php 
            echo("@include('include.test_include')");
        ?>
    );</script>

但我收到unexpected token 的错误。

我在文件夹views/include/test_include.blade.php中有一个视图

有没有办法做到这一点:)?

【问题讨论】:

  • 您为什么要尝试使用 JavaScript 加载刀片模板?您可以在模板中使用@include('include.test_include')
  • 不要在append函数中使用php标签,你应该直接包含像append('@include('include.test_include')')这样的包含视图文件
  • 我正在为月份加载一组日期...我必须能够删除一些日期。所以我会为每个月加载一个带有逻辑的视图..这个视图将显示日期..当我删除日期时,我只需要重新加载选定的月份视图

标签: javascript laravel include


【解决方案1】:

您应该能够在您的视图中执行此操作。

<script>
    $('#b').append(‘
        @include('include.test_include')
    ‘);
</script>I

【讨论】:

    【解决方案2】:

    将您的代码更改为以下内容:

    <script>
        $('#b').append('@include('include.test_include')');
    <script>
    

    更多关于包含子视图的文档in the Laravel documentation

    【讨论】:

      猜你喜欢
      • 2018-10-09
      • 2016-09-08
      • 2015-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-29
      • 1970-01-01
      相关资源
      最近更新 更多