Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

92
Views
¿Cómo mostrar ningún resultado encontrado en la búsqueda de Ajax Laravel?

Quiero mostrar 'No se encontraron resultados' en la búsqueda de Laravel Ajax. En mi caso si no hay registro me muestra una pantalla en blanco. Así que quiero cambiarlo a "No se encontraron resultados". ¿Alguien me puede ayudar?

Vista

 <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 answers
Answer question

0

Simplemente devuelva el 404 en "No se encontró ningún resultado" en el controlador.

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

Y agregue la función de error en la llamada ajax:

 $('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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!