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

141
Visualizações
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 Respostas
Responde à pergunta

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 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