duanbimo7212 2016-11-03 20:26
浏览 182

Laravel确认对话框

I'm looking for a simple way to confirm a delete of an item (I'm using Laravel 5.3)

I have this code:

<a href="{{url('/deleteProduct')}}<?='/'.$product->id;?>"><span class="glyphicon glyphicon-trash"></span></a>

So when clicking on the link, I call the route deleteProduct/{id}. But what I want is, that when clicking on the link, there is a prompt, saying something like sure to delete? yes/no. Only when clicking yes, this route is called then.

I tried it with a bootstrap modal and in general it worked, but I had problems with the $product, actually $product is an item in a foreach, so around the <a>-tag, there is a @foreach($products as $product). That's why the modal didn't work, because it got somehow messed up with this foreach (actually $product always held the last "product", because i defined it after the foreach).

Is there a easy to achieve what I want? Alternatively I could create a modal for every product, but there could be up to thousands of those, so this would be nonsense. So whats the better way?

Edit: The normal javascript function confirm() would work, but thats a little "too basic", so I want something that fits in the design, so something with bootstrap would be nice, or anything thats not a alert dialog with two buttons. The functionality of confirm is the one that I want. But also, confirm provides the buttons in english, I may want to customize those to be used in more then one language.

  • 写回答

1条回答 默认 最新

  • dongtang6718 2016-11-04 00:40
    关注

    I have achieved a pretty great results with SweetAlert plugin. There is actually an example of a delete with ajax. Check it out!

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?