Javascript Laravel成功后追加数据ajax
我有这个部门:Javascript Laravel成功后追加数据ajax,javascript,php,jquery,html,ajax,Javascript,Php,Jquery,Html,Ajax,我有这个部门: @foreach($bids as $b) <div class="bids notice notice-lg"> <strong>{{$b->user->name}}</strong> siūlo <span style="font-size: 18px" class="label label-success">{{$b->bid}} €</span> </div> @endfor
@foreach($bids as $b)
<div class="bids notice notice-lg">
<strong>{{$b->user->name}}</strong> siūlo <span style="font-size: 18px" class="label label-success">{{$b->bid}} €</span>
</div>
@endforeach
您可以返回视图并刷新包含出价的部分 在控制器中,将
$bids
返回到视图
,它将使用所有bids div构建html:
public function store(BidRequest $request, $id)
{
....
$bids = Bid::orderBy('bid', 'DESC')->paginate(10);
return view('products.show', compact('bids'));
}
然后在JS中,您将收到html,您只需将其附加到父容器:
success: function(data){
$('.bids_container').replaceWith(data);
}
希望这能有所帮助。如果您正在合并php和js,请尝试澄清您的具体问题并添加其他详细信息(如查看代码和控件)…我需要在提交表单时,DB中的值不会出现页面刷新。我的AJAX将它们插入数据库我只是不知道在我提交表单后如何显示它你可以添加将值插入数据库的操作吗,和显示它们的视图。@ZakariaAcharki我已经从BidController添加了一个函数,该视图的名称是什么?我现在从AJAX得到错误而不是成功的响应。是的,因为您正在使用
数据类型:“text'
在您的页面中检查我的答案。好的,我删除了它,我仍然需要刷新页面您的意思,您是否在成功回调中收到html?我们可以在聊天中讨论吗?
@foreach($bids as $b)
<div class="bidsA notice notice-lg">
</div>
<div class="bids notice notice-lg">
<strong>{{$b->user->name}}</strong>siūlo <span style="font-size: 18px" class="label label-success">{{$b->bid}} €</span>
</div>
@endforeach
public function store(BidRequest $request, $id)
{
$product = Product::where('id', $id)->first();
$bid = new Bid([
'product_id' => $product->id,
'bid' => $request->bid,
]);
Auth::user()->bid()->save($bid);
}
}
public function store(BidRequest $request, $id)
{
....
$bids = Bid::orderBy('bid', 'DESC')->paginate(10);
return view('products.show', compact('bids'));
}
success: function(data){
$('.bids_container').replaceWith(data);
}