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

243
Visualizações
How do I write Ajax syntax to retrieve data from an SQL database

I am trying to retrieve a particular column in my SQL database using Ajax, Javascript to a button without refreshing the whole page but only the button. I am new to Javascript and AJAX. How can I achieve that. I am using MVC.

    function GetId()
    {
        $("#display").onclick(function(){
        $.ajax({
            type: "POST",
            url: "Default.asp/Connection",
            data: "{}",
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            success: OnSuccess,
            error:OnError,

            success: function(data){
                displaybuttonFromDatabase();
            }
        });

    }
    function OnSuccess(data){
        var TableContent = "<table border = '0'>" +
                        "<tr>" +
                            "<td>Employee_Identification_No</td>" +
                        "</tr>";

        for(var i = 0; i<data.d.length;i++)
        {
            TableContent += "<tr>" +
                                "<td>" + data.d[i].Employee_Identification_No + "</td>" +
                                "<td></td>" +
                            "</tr>";

        }

        TableContent += "</table>";

        $("#UpdatePanel").html(TableContent);

    }
    function OnError(data) {

    }

    function displaybuttonFromDatabase() {
        $.ajax({
            url: "server",
            type: "POST",
            asyn: false,
            data: {
                "display": 1
            },
            success: function(data){
                $("#display").html(data);
            }
        })
    }
    });

I have also tried activating the button upon the click event. Tried this code

 function loadmyStaffData()
    {
      var name = document.getElementById("Employee_Identification_No");

       if (name != null)
        {
            $.ajax({
                type: 'post',
                url: '',
                data: {
                    Employee_Identification_No: name,
                },
                success: function(response){
                    $('#display').Html(response);
                }
            });
        }
        else
        {
            $('display').html('Re click this box')
        }
    }
about 4 years ago · Santiago Trujillo
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