【发布时间】:2018-09-30 14:09:36
【问题描述】:
我想从 html 中读取帖子 ID 并通过 AJAX 将其发送到控制器。如何获取帖子 ID ($post->id) 并通过 AJAX 传输?或者有没有更好的解决方案来保存用户看到的帖子?
@foreach ($posts as $post)
<div id="post_container_{{$post->id}}" class="row waypoint">
</div>
@endforeach
这是我的 AJAX 代码:
$('.waypoint').waypoint(function() {
$.ajax({
url: '/posts/view',
type: "post",
data:
success: function(request){
console.log(request);
},
error: function(response){
console.log(response);
},
headers:{
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
}, {
offset: '100%'
});
【问题讨论】:
-
您只需将
$post->id发送到服务器,对吧? -
是的,没错
标签: ajax laravel jquery-waypoints getvalue