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

101
Visualizações
how to call AJAX function in anchor tag

I'm new to AJAX. i want to call AJAX function when i click a button using onclick() event. This is the AJAX function called by onclick() event

function onclickFunction(aId){
    $.ajax({
        type: "get",
        url: "like_audio",
        data: {
            aId:aId
        },
        success: function (data){
            alert(data);
        },
        error: function (xhr, ajaxOptions, thrownError){

        }
    });
    return false;
}

This is how i'm calling the onclick() event

<a href="" onclick=onclickFunction(id)
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Just get the use return inside onclick, which will prevent the reload.

<a href="" onclick="return onclickFunction('id')">a</a>

As an alternative you can use

<a href="javascript:onclickFunction('id')">a</a>
over 4 years ago · Santiago Trujillo Relatório

0

<a href="#" onclick="onclickFunction('theid');">Click Me</a>

Will run the function, and pass it the value 'theid'

In your example, you don't have a comple href, and even if it was right, you might not have an ID value to pass to it. if i do this:

Click Me

I am basically saying, there is a variable called id in the global scope, go find its value and pass it to the function - if there is indeed a variable like that on your page, then it will work, however i don't know if there is.

over 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