I am using ExtJs 3.4 and I've implemented an Ajax request as following.
Ext.Ajax.request({
method: 'GET',
loadMask: true,
scope: this,
url: "http://" + host + ":" + port + "/" + projectName + "/"
+ "SetDefaultValues",
success: function (response, request) {
Ext.MessageBox.alert('success', response.responseText);
var jsonData = Ext.util.JSON.decode(response.responseText);
console.log(jsonData);
Ext.Msg.alert('Status', String(jsonData.name));
},
failure: function (response, request) {
Ext.MessageBox.alert('failure', response.responseText);
},
params : {
selectedVCode : selVehicleCode,
selectedFromDate : selFromDate.format('Y-m-d')
}
});
My Ajax response is like this.
{'defaultVal':[{ 'category' : '1', 'name' : 'Kamal Subhasingha' } , { 'category' : '2', 'name' : 'Namal Witharana' } , { 'category' : '3', 'name' : 'Yohan' } , { 'category' : '4', 'name' : 'Ahan Liyanage' } , { 'category' : '5', 'name' : 'Sampath Jayaweera' } , { 'category' : '6', 'name' : 'Saman' } ]}
I try to retrieve the fields from this data set. Here is my attempt.
success: function (response, request) {
Ext.MessageBox.alert('success', response.responseText);
var jsonData = Ext.util.JSON.decode(response.responseText);
console.log(jsonData);
Ext.Msg.alert('Status', String(jsonData.name));
}
This prints jsonData set in the console. It's ok. But it gives an alert with 'undefined'. It says 'String(jsonData.name)' is undefined.
What's going wrong with my codes.
Please help me to clarify this issue.