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

160
Visualizações
How to send get request when table head of a html page is clicked?

This is the html table and it has many table headers like s.no., first name, etc. So whenever any header is clicked I want to send a get request with the some values different for each headers.

The following is the table code I have used.

    <table class = "table" style = "margin-left:auto;margin-right:auto">
        <thead>
            <tr>
                <th id = "s.no.">S.No.</th>
                <th id = "fname">First Name</th>
                <th id = "lname">Last Name</th>
                <th id = "email">Email</th>
                <th id = "password">Password</th>
                <th id = "dob">Date of Birth</th>
                <th id = "gender">Gender</th>
                <th id = "hobbies">Hobbies</th>
            </tr>
        </thead>
        <tbody>
            {% for candidate in candidates%}
                <tr>
                    <td>{{candidate.id}}</td>
                    <td>{{candidate.fname}}</td>
                    <td>{{candidate.lname}}</td>
                    <td>{{candidate.email}}</td>
                    <td>{{candidate.password}}</td>
                    <td>{{candidate.dob}}</td>
                    <td>{{candidate.gender}}</td>
                    <td>{{candidate.hobbies}}</td>
                </tr>
            {% endfor %}
        </tbody>
    </table>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I hope this code will help you

let tableHead = document.getElementsByTagName("thead")[0];

tableHead.addEventListener("click", function(){
  httpRequest = (url, method = 'GET') => {
    return new Promise((resolve, reject) => {
      const xhr = new XMLHttpRequest();
      xhr.open(method, url);
      xhr.onload = () => {
        if (xhr.status === 200) { resolve(xhr.responseText); }
        else { reject(new Error(xhr.responseText)); }
      };
      xhr.send();
    });}  
});
    <table class = "table" style = "margin-left:auto;margin-right:auto">
        <thead>
            <tr>
                <th id = "s.no.">S.No.</th>
                <th id = "fname">First Name</th>
                <th id = "lname">Last Name</th>
                <th id = "email">Email</th>
                <th id = "password">Password</th>
                <th id = "dob">Date of Birth</th>
                <th id = "gender">Gender</th>
                <th id = "hobbies">Hobbies</th>
            </tr>
        </thead>
        <tbody>
                <tr>
                    <td>test</td>
                    <td>test</td>
                    <td>test</td>
                    <td>test</td>
                    <td>test</td>
                    <td>test</td>
                    <td>test</td>
                    <td>test</td>
                </tr>
        </tbody>
    </table>

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