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

459
Views
jQuery $.get o $.post para detectar el error de carga de la página (p. ej., 404)

¿Cómo detecta el error del servidor o la página 404 no encontrada cuando usa $.get o $.post?

Por ejemplo:

 $.post("/myhandler", { value: 1 }, function(data) { alert(data); });

Eso no hará absolutamente nada si hay un error del servidor al cargar "/ myhandler", o si no se encuentra.

¿Cómo haces que te notifique si hay un error?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Podrías hacerlo

 $.post("/myhandler", { value: 1 }, function(data) { alert(data); }).fail(function(){ // Handle error here });

se llamará a fail si hay un error

over 4 years ago · Santiago Trujillo Report

0

usar el controlador de error en $.ajax()

 $.ajax({ url: "/myhandler", data: {value: 1}, type: 'post', error: function(XMLHttpRequest, textStatus, errorThrown){ alert('status:' + XMLHttpRequest.status + ', status text: ' + XMLHttpRequest.statusText); }, success: function(data){} });

manifestación

over 4 years ago · Santiago Trujillo Report

0

Las otras respuestas son buenas y todo, pero hay soluciones alternativas, a saber, .ajaxSetup , .ajaxError y otros controladores de eventos Ajax (consulte la página de documentos de ajaxSetup para obtener más información sobre el resto).

Por ejemplo, con .ajaxError puede configurar un controlador global de todos sus errores ajax de .post , .get , .getJSON y .ajax para un conjunto específico de elementos.

 $(selector).ajaxError(function(event, xhr, ajaxOptions, errorThrown) { // handle ajax error here });
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!