小编hab*_*bib的帖子

如何将相同的数据传递给laravel中的多个视图

从控制器方法,我发送$notifications到主页视图并在我网站的标题上显示通知。

个人资料视图扩展了主页视图,我还想在个人资料视图上显示通知。

但是当我请求配置文件视图时,它会生成未定义变量 $notifications 的错误。

我认为一种解决方案是$notifications在从控制器方法返回配置文件视图时发送,但在网站中,我想在很多视图上显示通知选项卡,所以这是我正在思考的正确方式。

我通过以下方式返回了主页视图

return view('home')->with(['unseen_notification_counter'=>$unseen_notification_counter,'notifications'=>$notifications]);
Run Code Online (Sandbox Code Playgroud)

这是标题部分的主页视图中的代码

<ul class="dropdown-menu" id="notificationlist">
    @foreach($notifications as $notification)
        <li>
            <a href="{{route('user.profile',$notification->id)}}" class="dropdown-item">
                <img src="http://localhost/webproject/public/user_images/{{$notification->image}}" class="img-thumbnil" width="20px" height="20px">
                <strong>{{$notification->username}}</strong>
                <span style="white-space: initial;">sent you a friend request.</span>
            </a>
        </li>
    @endforeach
</ul>
Run Code Online (Sandbox Code Playgroud)

php laravel laravel-5 laravel-5.2

3
推荐指数
1
解决办法
3441
查看次数

ajax调用后Jquery事件绑定两次

我想在由 ajax 调用动态创建的元素上绑定一个事件。一些元素已经存在,并且在页面加载时会与它们绑定一个事件。但是当在 ajax 调用之后创建新元素时,新元素就会失去它们的绑定。

我搜索并找到了一个很好的解决方案。 ajax调用后不会触发Jquery事件

在这个问题中,“Jason Fingar”提出了两种解决方案来解决这个问题

  • 第二种解决方案是使用 on 方法,但对我不起作用
  • 第一种方法有效,但有些问题

这是他提出的第一个解决方案

“1)封装您的“绑定”代码并在页面加载时以及在相关元素添加回页面后立即调用它。例如:“

$(document).ready(function(){
// bind event handlers when the page loads.
bindButtonClick();
});

function bindButtonClick(){
$('.myClickableElement').click(function(){
    ... event handler code ...
});
}

function updateContent(){
$.ajax({
    url : '/ajax-endpoint.php',
    data : {'onMyWay' : 'toServer'},
    dataType : 'html',
    type : 'post',
    success : function(responseHtml){
        // .myClickableElement is replaced with new (unbound) html 
     element(s)
        $('#container').html(responseHtml);

        // re-bind event handlers to '.myClickableElement'
        bindButtonClick();  
    }
});
}
Run Code Online (Sandbox Code Playgroud)

我面临什么问题? 事件与新元素成功绑定,但对于旧元素或页面加载时加载的元素,事件绑定两次。这有什么问题?

javascript ajax jquery jquery-events

2
推荐指数
1
解决办法
1095
查看次数

删除 HTML5 视频播放器菜单按钮

我想从 HTML5 视频标签的视频控件中删除菜单按钮(“kebab”(三个垂直点))。

我对此进行了很多搜索并找到了一个相关问题,但在接受的答案中,用户给出了删除所有控件的说明,但我不想删除所有控件,但删除菜单按钮,如下所示。 在此输入图像描述

html css html5-video

2
推荐指数
1
解决办法
2641
查看次数