Flash cannot trigger after AJAX response



  • I create new packages, and add new pages also. I have to update data using Ajax and shows the flash-message to the user that the data is updated. But If I use window.flashMessages = [{ 'type': 'alert-success', 'message': 'Updated'}]; nothing shows in my page. If I use alert like success: function(response){ alert('Updated'); } then alert is showing. Any Idea to use flash message.



  • Hi @valpuia

    Can you attach your views master file, so that we can check.

    Thanks



  • Hi @rahul
    here's the blade file.. my route and controllers are working fine.

    @extends('admin::layouts.master')
    
    @section('page_title')
        {{ __('menus::app.menus.page_title') }}
    @stop
    
    @section('content-wrapper')
        <div class="page-content">
           <div class="dd" id="menuNestable">
             <ol class="dd-list">
               @foreach ($menus as $menu)
                 <li class="dd-item dd3-item" data-id="{{ $menu->id }}" >
                  <div class="dd-handle dd3-handle"></div>
                 </li>
                @endforeach
              </ol>
           </div>
          </div>
    @endsection
    
    @push('scripts')
        <script src="/js/jquery.nestable.js"></script>
        <script>
          $('#menuNestable').on('change', function() {
             var dataString = { 
                data : $("#nestable-output").val(),
            };
          
           $.ajaxSetup({
            headers: {
              'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
          });
          
          $.ajax({
            type: "POST",
            url: "{{ route('menus.update') }}",
            data: dataString,
            cache : false,
            success: function(response){
              // alert('Updated');
              window.flashMessages = [{
               'type': 'alert-success',
               'message': 'Updated'
              }];
            }, error: function(xhr, status, error) {
                alert(error);
            },
          });
        });
      </script>
    @endpush
    


  • Hi @valpuia

    Try with this one -

     window.flashMessages = [{
              'type': 'alert-success',
             'message': 'Updated'
     }];
    
    this.$root.addFlashMessages()
    

    Thanks


Log in to reply