Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

95
Visualizações
How to show no result found in Ajax Laravel search?

I want to show 'No Results Found' in the Laravel Ajax search. In my case, if there is no record, it shows a blank screen. So I want to change it to "No results found." Can someone help me?

View

<div class="row" style="text-align: center;padding-top: 25px;">
     <div class="col-md-8" >
          <h2 id="dynamic-row"></h2>
     </div>
</div>    
<script>
    $('body').on('click' ,'#search' , function(){
        var from = $('#from').val();
        var to = $('#to').val();
        $.ajax({
            method: 'POST',
            url: '{{ route("fare.search") }}',
            dataType: 'json',
            data: {
                '_token' : '{{ csrf_token() }}',
                from : from,
                to: to,
            },
            success: function(res){
                var tableRow = '';
                $('#dynamic-row').html('');
                $.each(res , function(index,value){
                    tableRow = '<h2>RS &nbsp;'+value.fare+'/-</h2>';                   
                    $('#dynamic-row').append(tableRow);
                    //$('#dynamic-row').css('font-weight', 'bold');
                    
                })
            }
        })
    })
</script>
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Just simply return the 404 on "No result found" in Controller.

return response()->json('No Result Found', 404);   

And add the error function in ajax call:

$('body').on('click' ,'#search' , function(){
        var from = $('#from').val();
        var to = $('#to').val();
        $.ajax({
            method: 'POST',
            url: '{{ route("fare.search") }}',
            dataType: 'json',
            data: {
                '_token' : '{{ csrf_token() }}',
                from : from,
                to: to,
            },
            success: function(res){
                var tableRow = '';
                $('#dynamic-row').html('');
                $.each(res , function(index,value){
                    tableRow = '<h2>RS &nbsp;'+value.fare+'/-</h2>';                   
                    $('#dynamic-row').append(tableRow);
                    //$('#dynamic-row').css('font-weight', 'bold');
                    
                })
            },
            error: function(res){
              console.log(res);
            }
        })
    })

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda