I have a MVC controller where I am converting the datatable result using JsonConvert.SerializeObject
and returning as follows
public JsonResult GetJson(DateTime StartDate)
{
DataTable dt = new DataTable();
using (SqlConnection con = new SqlConnection(context.Database.Connection.ConnectionString))
{
using (SqlCommand cmd = new SqlCommand("usp_GetDetails"))
{
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@startdate", SqlDbType.DateTime);
cmd.Parameters["@startdate"].Value = StartDate;
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
sda.Fill(dt);
}
}
}
return Json(new { success = true, data = JsonConvert.SerializeObject(dt) },
JsonRequestBehavior.AllowGet);
}
But the same is working inside fiddle when I copy the result that I am getting
https://jsfiddle.net/szq2ker4/1/ This is how I am making an ajax call in jquery and doing the rest as per fiddle but I am not seeing the expected as per in the fiddle
$.get("/controller/GetJson", { StartDate: date},
function (response) { var result = JSON.parse(response.data);})
The result I am getting is as follows, can some one let me know where I am doing wrong
$.get("/controller/GetJson", { StartDate: date},
function (response) { var result = JSON.parse(response.data);}).fail(function (response) { **alert('failed')**;});