Laravel @通过Ajax包含刀片视图 [英] Laravel @include a blade view via ajax

查看:81
本文介绍了Laravel @通过Ajax包含刀片视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面,其中将包含一些内容,我想使用ajax请求@include该刀片视图文件.我应该怎么做.

I have a page which will @include some content, I want to @include that blade view file using ajax request. How should I do it.

基本上,视图文件将从服务器获取项目,

Basically, the view file will get the items from server,

**price.blade.php**
@foreach ($items as $item)
<div class="item-post">
  <div class="priceofitem">{{ $item->price }} </div>

我想在我的标签部分添加@include('price.blade.php')

I want to include @include('price.blade.php') in my tab section

<ul class="tabs">
<li><a href="#tab1">Prices </li>
<div id="tab1">@include('price.blade.php')</div>

我不想在加载时自动包含该视图文件,因为我不想加载该选项卡的内容,除非用户单击它,如果用户想要的价格高于用户单击该选项卡的价格,并且AJAX请求将被发送以包含该文件.

I don't want to include that view file automatically upon load, as I don't want to load that tab's content unless the user clicks on it, if the user wants the prices than the user clicks on that tab, and an AJAX request will be sent to include that file.

希望我让自己清楚了,如果您不了解我,请告诉我.

Hope I made myself clear, please let me know if you did not understand me.

手指交叉

推荐答案

您想要

$(document).ready(function() {
    $("#tab1").click(function() {
        $.ajax({
            type: 'POST', 
            url : "/yourrouteview", 
            success : function (data) {
                $("#tab1").html(data);
            }
        });
    });
}); 

您的控制器和路由必须配置/yourrouteview以获得正确的视图(即@include('price.blade.php')

Your controller and route must configure /yourrouteview to get the correct view (that is @include('price.blade.php')

这篇关于Laravel @通过Ajax包含刀片视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆