栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用ajax从数据库获取关于帖子的评论

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用ajax从数据库获取关于帖子的评论

表单代码更新。

@foreach($posts as $post)   <p>$post->description</p>    <div ></div>  // I found this pre on laracast, at end there is link.   @if (count($post->comments))       @foreach($post->commnents as $comment)         <small>$comment->body</small>       @endforeach    @else         No comments Found  @endif

将数据存储在json响应中。

if($request->ajax()){    $comment = new Comment;    $comment->user_id =  Auth::user()->id;    $comment->post_id = $post_id;    $comment->body = Input::get('body');    $comment->save();   //add the comment in response     return response()->json(['msg'=>$comment->body]);}

在ajax中需要显示消息,我们已经成功添加了数据

$.ajax({        type: "POST",        url: '/comment/'+post_id,        data: {body:body, post_id:post_id, user_id:user_id,  _token: '{{csrf_token()}}'},        success: function(data) { //get the msg from success response.     $(".show_comments_"+post_id).append("<div style = 'color:red;'>"+data.msg+"</div>");        }    });


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/413482.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号