Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

206
Vistas
Why ajax HTTP POST gets an empty response from server?

I am trying to do a POST request in ajax in this way:

$.ajax({
                type: "POST",
                url: 'http://192.168.1.140/',
                data: "{}",
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                success: function (data) {
                   alert(data);
                },
                error: function (data, success, failure) {
                    alert("Error:" + failure);
                }
            });

The server I have at that IP only do this:

<?php
echo "test"
?>

In the alert I only get the word 'Error' from the error function and nothing else from the parameters. I don't know where is the problem. I want it to display in the alert the word 'test' that the servers sends. Can anyone tell me what I am doing wrong?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The reason you're getting an error is because you're telling jQuery ajax that this request will return a json response but you just return plain text.

I'm not sure why your errorThrown is blank as it should show parse error.
You can just have alert("Error:" + data.responseText); to alert the result.

To avoid the error you can echo json in your php script echo '{"test":true}'
or remove the dataType: "json", in your request.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda