In school we use ASP.NET but normally I am a RoR developer.
I get my data from a WCF service. I have created this ASP.NET MVC 5 project. I created a controller that looks like this:
[HttpGet]
public ActionResult GetMovies()
{
return Json(client.RetrieveAllFilms(), JsonRequestBehavior.AllowGet);
}
And a on load jquery script that looks like this at the following moment:
<script>
$(document).ready(function () {
console.log("document ready");
$.ajax(
{
type: "GET",
dataType: 'json',
url: "http://localhost:5348/movies/getmovies",
data: "",
success: function(data)
{
alert(data.d);
var list = JSON.stringify(data.d);
alert(list);
for (var i = 0; i < list.length; i++) {
alert(list[i].Description);
}
},
error: function(data)
{
alert("ERROR");
}
});
});
</script>
The problem:
The problem is that when i say http://localhost:5348/movies/getmovies in the postman app then it gives me a lot of JSON but when I use the jquery script then I get an empty array which it my variable list.
Hope someone can help here.
Up front thanks ;)
RetrieveAllFilms()
?) and a collection does not contain a property namesd
(as indata.d
). And its already json so trying to stringify it would also be an error. If you want to loop through your list then$.each(data, function(index, item) { console.log(item.Description); }
stringify
iedd
(then trying to iterate through astring
)