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 :) ?

3
  • Why are you trying to load a blade template with JavaScript? You can just use @include('include.test_include') in your template. Commented Feb 25, 2019 at 12:58
  • Do not use php tag into append function, You should include directly include view file like append('@include('include.test_include')') Commented Feb 25, 2019 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 Commented Feb 25, 2019 at 13:30

2 Answers 2

2

Change your code to the following:

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

More documentation on including subviews in the Laravel documentation

Sign up to request clarification or add additional context in comments.

Comments

2

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.