Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

242
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!