I confess, its a very basic question. But I am actually fed up with it. I am just trying to send my current time in JSON format from my action method to the view. In the view code, I am trying to fetch the result using jQuery ajax() method. But while in the success attribute, I am unable to fetch the result from the response. Tried numerous ways like response.d etc. But ended up with nothing almost.
Here goes the relevant code snippets:
Action method:
public JsonResult GetDateTest()
{
return Json(DateTime.Now.ToString(), JsonRequestBehavior.AllowGet);
}
script in the view:
<script type="text/javascript">
$(document).ready(function () {
$("#Button1").click(function (e) {
$.ajax({
type: 'POST',
url: '@Url.Action("GetDateTest","GetDate")',
data: '{}',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (response) {
//how can I read the date here and display it on the standard //controls like a label?
},
error: function (e) {
alert("error");
}
});
});
});
</script>
Help me to figure it out with proper explanation
responseobject looks like, then you'll know what property to access in it.