首页 > 解决方案 > 如何在提交按钮单击php时提示sweetalert

问题描述

在此处输入图像描述我正在研究 php laravel 框架。我需要提示一个甜蜜的警报,显示单击提交按钮时的条款和条件。我不知道使用甜蜜警报。我只是使用了一些模板并编写了以下代码。它不工作。谁能帮我这个

@extends('layouts.app')
@section('maincontent')
<div class="login-form">
    <div class="container">
        <div class="row ">
            <div class="innerpage-box">
                @include('layouts.errors')
                <div class="innerpage-box-header text-center">
                    <h3></b>Products to Buy</h3>
                </div>
                <div class="register-box-body">
                    <!-- <p class="login-box-msg">REGISTRATION FORM</p> -->
                    <form role="form" id="myForm" action="/chemOrderSave" method="Post" class="bidDetailSave">
                        @csrf
                        <input type="hidden" name="product_id" value="{{$pro[0]->id}}">
                        <div class="row">
                    
                            <div class="col-md-6">
                                <label> <b> Price: </b>
                                    {{$pro[0]->price * 1.02}}
                                </label> </br>
                                
                                <div class="form-group">
                                    <label for="buyer_quantity"><b> Quantity </b> <star>*</star></label>
                                    <input type="text" class="form-control" id="buyer_quantity" name="buyer_quantity" placeholder="Enter the Quantity" value="{{$pro[0]->quantity}}">
                                </div>


                                <div class="form-group">
                                    <label for="chem_shipping">Shipping</label>
                                    <select name="chem_shipping" class="form-control" required>
                                        <option value="">Please select one of the following Shipping Addresses</option>
                                        @foreach($us as $uss)
                                        <option value="{{$uss->id}}" > {{$uss->address}} {{$uss->city}} {{$uss->state}} {{$uss->zipcode}} {{$uss->country}} </option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>
                                <button type="submit" class="btn btn-success updateOrder" ><i class="fa fa-save"></i> Submit</button>
                                <a href="/chemClearDashboard/Buyer/{{$pro[0]->user_id}}" class="btn btn-danger" style="font-size: 1rem !important;"><i class="fa fa-close"></i> Cancel</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

在 custom.js 我写了以下代码

 $('.container').on('click', '.updateOrder', function() {
        //e.preventDefault();
        var id = $(this).attr('id');
        var title = "Are you sure, By Clicking accept you agree to Farmerce's user agreement and are agreeing to follow through on this transaction !";
        swal({
            title: title,
            type:'warning',
            showConfirmButton: true,
            showCancelButton: true,
            allowOutsideClick: false,
            confirmButtonText:'Confirm',             
        }).then((result) => {
            if (result.value) {
                $.ajax({
                    type: 'post',
                    url: '/chemBuyer',
                    data: {'_token': $('input[name=_token]').val(), 'id':id},
                    success: function(data) { 
                        if(data == 'success'){
                            var title= 'Successfully Order Placed!!!';
                            var type='success';
                        }else{
                            var title= 'Some thing went wrong with the '+name+' !!!';
                            var type='error';
                        }
                        swal({
                            title: title,
                            type:type,
                            showConfirmButton: true,
                            confirmButtonText:'OK',
                        }).then(function(){
                            window.location.reload();
                        });
                    }
                });
            }
        })
    });

标签: javascriptphplaravelsweetalert

解决方案


推荐阅读