I have retrieved JSON data from the controller using AJAX and now I want to access this data. The data is in the form of a list of objects (array) with key-value pairs, so I am planning to use .each() function to go through all the data. The array looks like this:
[{"filePath":"Desktop.zip","fileStatus":"Uploaded"},{"filePath":"Desktop\\dates.xml","fileStatus":"Uploaded"}]
Here is the code snippet:
$.ajax({
url: '@Url.Action("GetFilesNames", "Home")',
type: 'POST',
success: function (data) {
$.each(data, function (value) {
console.log(value['filePath'], value['fileStatus']);
});
}
});
https://i.sstatic.net/CUbZt.png
However, the value for each data entry is coming out as undefined.
I have tried logging all the data, stringifying it, parsing it (which resulted in errors), and even converting the stringified version into an object. But no matter what I try, when using .each(), the result remains undefined.