Append blade file to jquery function

谁说我不能喝 提交于 2021-02-07 19:54:40

问题


IS there any way to achieve this:

<script>
    $('#appends').append('<div class="content-section" id="services">' + 
    " @include('visitor.pages.services') " + 
    ' </div>');
</script>

What i want is to append the content of visitor.pages.services to #appends div

visitor.pages.services is not a php url or something. It is just some lines of html where i am including in my main page.

this is the file

<div class="container">
    <div class="row">
        <div class="heading-section col-md-12 text-center">
            <h2>Our Services</h2>
            <p>We design mobile-first websites for you</p>
        </div> <!-- /.heading-section -->
    </div> <!-- /.row -->
    <div class="row">
        @foreach($data['services'] as $service)
            ... bla bla
        @endforeach
    </div> <!-- /.row -->
</div> <!-- /.container -->

回答1:


As your question says, you want to get the content of the file and append it to the specific element.

Use $.get()

$.get("visitor.pages.service.html", function(data){
    $('#appends').append(data);
});

OR .load()

$('#appends').append( $('<div>').load('visitor.pages.service.html'));

OR .ajax()

$.ajax({
    url: "your.html",
    success: function (data) { $('#appends').append(data); },
    dataType: 'html'
});


来源:https://stackoverflow.com/questions/40219773/append-blade-file-to-jquery-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!