save old data after refresh page with ajax

Posted 1 year ago by coder_uzb

HI guys. I have select box and I use on change method with ajax. This is my select box

<select class="select js-delivery" name="delivery_id">
                                    <option selected disabled>Choose delivery type</option>
                                    @foreach($deliveries as $delivery)
                                        <option value="{{$delivery->id}}">{{ $delivery->title }}</option>
                                    @endforeach
                                </select>

and here my ajax.

$(document).on('change', '.js-delivery', function(e){
            delivery.show();
            var delivery_id = $(this).val();            
                $.ajax({
                    type:'GET',
                    url:'get/delivery', 
                    data: {'id':delivery_id},
                    success:function(data){

                    var type = $('.delivery-type');
           type.html(data.title);   
                    },
                    error:function(data){
                        console.log('error');
                    }      
                });
        });

After this I submitted form and page refreshed. But when I was laravel errors I am losing select box value. How can I save old data?

Please sign in or create an account to participate in this conversation.