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

136
Vistas
very simple ajax doesn't work

I am fiddling with ajax, the following doesn't work:

$(document).ready(function() {
  $("button").click(function() {
    $.post("\tests\test1.php", function(data) {
      alert(data)
    });
  })
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

<button>Click</button>

with test1.php

<?php

echo "Yes";

?>

The url is with respect to htdocs, so correct. Please point out the error.

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You are using an incorrect url: never use "\tests\test1.php"

Instead "/tests/test1.php" is the correct approach.

So your code becomes:

$.post( "/tests/test1.php", function( data ) {
    alert(data);
});

I would also recommend you to use the full URL exaple:

http://example.com/tests/test1.php

instead of /tests/test1.php. (although not required but considered as a good approach.)

about 4 years ago · Santiago Trujillo 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