Hi there, I'm currently working in Visual Studio with ASP.NET and Razor. I am trying to populate a table with values from a database table, but I need to decode or parse JSON into simple text first. Any assistance would be greatly appreciated. Here is the code snippet that I am currently using: https://i.sstatic.net/K7imY.png
[HttpGet]
public ActionResult GetData()
{
string stdb = "Data Source=DMX87025;Initial Catalog=DB_PCC;Integrated Security=True";
SqlConnection conn = new SqlConnection(stdb);
string sql = "SELECT *FROM[DB_PCC].[dbo].[Departments]";
SqlCommand cmd = new SqlCommand(sql, conn);
conn.Open();
SqlDataReader rd = cmd.ExecuteReader();
var st = "kyo please help me u.u";
return Json(new { success = true, message = rd },
JsonRequestBehavior.AllowGet);
}
<div id="result"></div>
<input type="button" name="name" value="try" onclick="DepListQuery()" />
<script>
function DepListQuery() {
$.ajax({
type: 'GET',
url: '@Url.Action("GetData","Home")',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
$('#result').text(response.message);
},
failure: function (response) {
alert("something went wrong u.u");
}
});
}
</script>