如何解决我想在我的网站顶部显示我的商店位置,该位置可以由用户在laravel网站中单击并更改位置
在我的购物站点中,我想显示我的商店位置,用户可以单击并选择附近的商店。我尝试使用JQuery
的工作,但刷新时将其更改为默认值。我想显示由用户选择的存储位置,在会话销毁时不应更改它,而只需更改为默认值即可
我的header_popup页面
@foreach(session('locs') as $id => $details)
<i class="fa fa-map-marker"></i> <button class="mystore" data-toggle="modal" data-
target="#myModal" id="mymodl" value="mymodl" data-id="">
{{ $details['area']}}
@endforeach
<span id="status"></span>
</button>
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Choose your nearby store</h4>
<div class="modal-body header-pop-buton">
@foreach($user as $store)
<button class="mystore" data-id="{{ $store->id }}" value="{{ $store->area }}" >{{
$store->area }}</button>
@endforeach
</div>
</div>
我的脚本
<script>
$(".mystore").on('click',function (e) {
e.preventDefault();
var ele = $(this);
$.ajax({
url: '{{ url('header-loc') }}' + '/' + ele.attr("data-id"),method: "get",data: {_token: '{{ csrf_token() }}'},dataType: "json",success: function (response) {
$("span#status").html('<div class="alert alert-success">'+response.msg+'</div>');
$("#header-bar").html(response.data);
}
});
$('#myModal').modal('hide');
});
</script>
在我的布局中,我使用@include(header_popup)
我的控制器
public function headerloc(Request $request,$id)
{
$product = store::find($id);
// if cart is empty then this the first product
if ($locsd) {
$locsd = [ $id => ["area" => $product->area]];
session()->set('locs',$locsd);
$htmlCart = view('header_popup')->render();
return response()->json(['msg' => 'Product added to cart successfully!','data' =>
$htmlCart]);
//return redirect()->back()->with('success','Product added to cart successfully!');
}
}
提前谢谢
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。