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

128
Visualizações
Sending GET Request when Button is Clicked

I'm attempting to send a GET request as soon as a button is pressed. As I'm quite inexperienced with HTML and JQuery/Ajax, I'm a little bit confused as to how to do this. My code is as following

  <div id = "Reset">
  <!-- <form method="get"></form> -->
  <!-- <form action="https://wt.ops/reset" method="get"> -->
  <button>Reset</button>
  <!-- </form> -->
  </div>
 <script>
      $("Reset").ready(function(){
        $( "#Reset" ).click(function(){});
        $.get( "https://wt.ops/reset", function( data ) {
          $( ".result" ).html( data );
          alert( "Load was performed." );
        })});

      </script>

Currently what it's doing is that it just loads the JQuery scripts automatically when the page is reloaded. But when I click the button, it does nothing.

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

You should attach the click handler after the document is loaded.

$("document").ready(function(){
    //.. click handler
});    

Your $.get should be within the click handler.

    $("#Reset").click(function(){
        $.get( "https://wt.ops/reset", function( data ) {
            $( ".result" ).html( data );
            alert( "Load was performed." );
        });
    });
about 4 years ago · Juan Pablo Isaza Relatório

0

Few things you have to update

1. this is just to ask have you added the jquery script in head

2. You have to change the id from div to button tag or remain as it is

<div>
    <!-- <form method="get"></form> -->
    <!-- <form action="https://wt.ops/reset" method="get"> -->
    <button id="Reset">Reset</button>
    <!-- </form> -->
</div>

3. You have to update the script function to below function. I have only changed the url to check the data

$(document).ready(function () {
        $("#Reset").click(function () {
            $.get("https://jsonplaceholder.typicode.com/todos", function (data) {
                console.log(data);
                alert("Load was performed.");
            })
        });
    });
about 4 years ago · Juan Pablo Isaza Relatório

0

I see you use Jquery.

  <div id = "reset">
  <button  >Reset</button>
  <span id='result'> data</span>
  </div>

  $().ready(function(){
      
        $( "#reset" ).click(function(){
        console.log('click')
        getFileFromNet();
        });
        
        function getFileFromNet(){
         $.get( "https://rickandmortyapi.com/api/character/2", function( data ) {
          $( "#result" ).html( data );
          alert( "Load was performed." );
          
        })
        }
        });

https://jsfiddle.net/eaLjb1n5/

Maybe it help you

about 4 years ago · Juan Pablo Isaza 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