Hi micah,
Refer below sample.
HTML
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$.ajax({
type: "POST",
url: "CS.aspx/GetData",
data: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
var xmlDoc = $.parseXML(response.d);
var xml = $(xmlDoc);
var customers = xml.find("Table");
var rows = '';
$.each(customers, function () {
var id = $(this).find("CustomerId").text();
var name = $(this).find("Name").text();
var country = $(this).find("Country").text();
rows += "<tr><td>" + id + "</td><td>" + name + ' ' + "</td><td>" + country + "</td></tr>";
});
$('.tblCustomers tbody').append(rows);
},
error: function (response) {
var r = jQuery.parseJSON(response.responseText);
alert("Message: " + r.Message);
}
});
});
</script>
<div>
<table class="tblCustomers" border="1">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Contry</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
Namespaces
C#
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using System.Web.Services;
VB.Net
Imports System.Data.SqlClient
Imports System.Web.Services
Imports System.Data
Code
C#
[WebMethod]
public static string GetData()
{
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ToString()))
{
SqlCommand cmd = new SqlCommand("SELECT CustomerId,Name,Country FROM CustomerTest");
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataSet ds = new DataSet())
{
sda.Fill(ds);
return ds.GetXml();
}
}
}
}
VB.Net
<WebMethod()>
Public Shared Function GetData() As String
Using con As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("constr").ToString())
Dim cmd As SqlCommand = New SqlCommand("SELECT CustomerId,Name,Country FROM CustomerTest")
Using sda As SqlDataAdapter = New SqlDataAdapter()
cmd.Connection = con
sda.SelectCommand = cmd
Using ds As DataSet = New DataSet()
sda.Fill(ds)
Return ds.GetXml()
End Using
End Using
End Using
End Function
Screenshot