Within my MVC controller, I have implemented a method to query a database and return a JSON object. To achieve this, an ajax call is necessary to provide a date for the database query. However, I am encountering an issue where null
is being passed to the controller within my current configuration.
Here is an excerpt from my ajax request:
$(document).ready(function () {
setInterval(function () {
$.ajax({
type: "POST",
url: '@Url.Action("GetChartData", "Plot")',
dataType:'json',
data: '04-15-2019 15:49:00',
success: function (result) {
console.log(JSON.parse(result));
}
});
}, 10000);
});
The corresponding controller code looks like this:
[HttpPost]
public JsonResult GetChartData(string timeStamp)
{
string output = queryDatabase(timeStamp);
string jsonOutput = new JavaScriptSerializer().Serialize(output);
return Json(output, JsonRequestBehavior.AllowGet);
}
When analyzing the code flow after calling queryDatabase
, the timeStamp
variable consistently appears as null
. What could be the underlying cause of this issue?
Any insights or suggestions would be greatly appreciated!