1

I try to include views in my page via javascript using the following script:

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

But I get an error of unexpected token.

I have a view in folder views/include/test_include.blade.php

Is there a way to do this :) ?

Derk Jan Speelman
  • 11,291
  • 4
  • 29
  • 45
KbZuhn
  • 57
  • 1
  • 7
  • Why are you trying to load a blade template with JavaScript? You can just use `@include('include.test_include')` in your template. – George Hanson Feb 25 '19 at 12:58
  • Do not use php tag into append function, You should include directly include view file like `append('@include('include.test_include')')` – Amit Senjaliya Feb 25 '19 at 13:00
  • I'm loading a set of dates for month...and i must be able to remove some dates. So i will load a view with logic for every month ..this views will display dates..and when i remove dates, i only have to reload the selected month view – KbZuhn Feb 25 '19 at 13:30

2 Answers2

2

Change your code to the following:

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

More documentation on including subviews in the Laravel documentation

Douwe de Haan
  • 6,247
  • 1
  • 30
  • 45
2

You should just be able to do this in your view.

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