I'm trying to pass a list object from the server to an Ajax success callback, but I'm not receiving data in the console, and the alert
calls in my code don't fire.
I don't have much experience with JS, and I haven't been able to determine why this isn't working. I've already tried changing ActionResult
to JsonResult
, to no avail.
This is the action method:
public ActionResult jason()
{
var list = new CardModel().ItemList;
return Json(list);
}
And this is the Ajax call:
<script>
$(document).ready(function() {
$.ajax({
type: 'GET',
url: "/Card/jason/",
dataType: 'json',
success: function myfunction(data) {
console.log(data);
var list = data;
console.log(list);
$.each(list, function(index, item) {
alert(item);
});
}
});
});
</script>