javascript - Append blade file to jquery function - Stack Overflow

IS there any way to achieve this: <script>$('#appends').append('<div class=&quo

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 -->

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 -->
Share Improve this question edited Oct 24, 2016 at 13:58 Mohit Tanwani 6,6382 gold badges15 silver badges33 bronze badges asked Oct 24, 2016 at 13:30 IraklisIraklis 2281 gold badge5 silver badges17 bronze badges 3
  • You need to include more info about 'visitor.pages.services' if Loading..'s answer didn't fix your problem. – Andrew Commented Oct 24, 2016 at 13:44
  • 1 @Andrew I fixed the problem by creating a url for this partial. btw i am in Laravel. Now i have another problem in passing $data['services']. If you have some idea please share :) – Iraklis Commented Oct 24, 2016 at 13:51
  • Actually i fixed it all. Thanks a lot :))) – Iraklis Commented Oct 24, 2016 at 13:53
Add a ment  | 

1 Answer 1

Reset to default 7

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'
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745547796a4632421.html

相关推荐

  • javascript - Append blade file to jquery function - Stack Overflow

    IS there any way to achieve this: <script>$('#appends').append('<div class=&quo

    5小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信