将刀片文件附加到 jquery 函数 [英] Append blade file to jquery function

查看:30
本文介绍了将刀片文件附加到 jquery 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法可以做到这一点:

我想要的是将 visitor.pages.services 的内容附加到 #appends div

visitor.pages.services 不是 php url 或其他东西.这只是我在主页中包含的一些 html 行.

这是文件

<div class="row"><div class="heading-section col-md-12 text-center"><h2>我们的服务</h2><p>我们为您设计移动优先网站</p>

<!--/.heading-section -->

<!--/.row --><div class="row">@foreach($data['services'] 作为 $service)... bla bla@endforeach

<!--/.row -->

<!--/.container -->

解决方案

正如您的问题所说,您想获取文件的内容并将其附加到特定元素.

使用$.get()

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

OR .load()

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

OR .ajax()

$.ajax({网址:你的.html",成功:函数(数据){ $('#appends').追加(数据);},数据类型:'html'});

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

解决方案

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

这篇关于将刀片文件附加到 jquery 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
前端开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆