When I run the following code in my JSFiddle:
var data = {
"webservice_status" : {
"status" : "SUCCESS",
"message" : ""
},
"fileNamePathList" : [ {
"fileName" : "employee_file"
} ]
}
console.log(data.fileNamePathList[0].fileName);
I can see my console log printing the file name properly. However, when I run the following Ajax call :
$.ajax({
url: fileUrl + "?refDataID=" + refdata,
success : function(data) {
// alert('Data insife File Name: '+data.fileNamePathList.fileName);
console.log('Data insife File Name: ');
console.log(data);
console.log(data.fileNamePathList[0].fileName);
},
error : function(request,error)
{
alert("Request: "+JSON.stringify(request));
}
});
It prints the same JSON as above with this statement console.log(data);
. However, I get TypeError: data.fileNamePathList is undefined
error with this console.log(data.fileNamePathList[0].fileName);
What am I doing wrong? Thanks !