最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Disabling button until process is complete - Laravel - Stack Overflow

programmeradmin1浏览0评论

I have a page where users can place orders, Order numbers increment.

Is it possible to disable the button until the process is plete? i.e until the order is successfully placed.

What my clients face is, when they click on the place order button, the process bees slow since their network is bad. Unknowingly, they click the place order again assuming the process failed. At the long run, they will have orders of the same items (duplicates). 001, 002, 003 all having the same food items since they keep clicking on the place button.

Code

 public function save(Request $request)
 {
    $food = new Food(array(
        'name'  => $request->get('name'),
        'price' => $request->get('price'),
    ));

    return redirect('admin')->with('status','Order successfully placed');
}

I have a page where users can place orders, Order numbers increment.

Is it possible to disable the button until the process is plete? i.e until the order is successfully placed.

What my clients face is, when they click on the place order button, the process bees slow since their network is bad. Unknowingly, they click the place order again assuming the process failed. At the long run, they will have orders of the same items (duplicates). 001, 002, 003 all having the same food items since they keep clicking on the place button.

Code

 public function save(Request $request)
 {
    $food = new Food(array(
        'name'  => $request->get('name'),
        'price' => $request->get('price'),
    ));

    return redirect('admin')->with('status','Order successfully placed');
}
Share Improve this question edited Oct 19, 2018 at 12:47 Pratik Gadoya 1,4831 gold badge17 silver badges28 bronze badges asked Jan 5, 2018 at 12:09 LearnLaravelLearnLaravel 4033 gold badges9 silver badges24 bronze badges 5
  • 2 How are you submitting the order? If you are using ajax then you can disable the button before the ajax query and then enable it again once the client receives a response. Your question is lacking important detail and source code of what you have tried so far. – NewToJS Commented Jan 5, 2018 at 12:13
  • 1 Post the code of submitting the order pls – Luis felipe De jesus Munoz Commented Jan 5, 2018 at 12:14
  • @NewToJS, i save my order the standard way its been done in laravel for store not with ajax. Kindly check my update – LearnLaravel Commented Jan 5, 2018 at 12:17
  • @LuisfelipeDejesusMunoz please check my update – LearnLaravel Commented Jan 5, 2018 at 12:17
  • 1 You could disable the button with javascript and add a loading icon. – Jerodev Commented Jan 5, 2018 at 12:22
Add a ment  | 

1 Answer 1

Reset to default 5

You can disable form's submit button after clicking on submit button using jQuery.

<script>
$(document).ready(function() {
    $(document).on('submit', 'form', function() {
        $('button').attr('disabled', 'disabled');
    });
});
</script>
发布评论

评论列表(0)

  1. 暂无评论