I am calling service to get languages based on country. when it returns multiple languages my following code is working fine.. but when it returns only one record the output is not coming correctly(coming as "indefined".. please advice.
here is my code:
$.ajax({
type: 'POST',
url: "http://mymethod",
complete: function () { $.mobile.hidePageLoadingMsg(); },
dataType: "json",
contentType: 'application/json',
data: JSON.stringify({
"country": countryCode
}),
success: function (output, textStatus, jqXHR) {
$.each(output.geographyInfo, function (i, theItem) {
try {
languages.push("<option value='" + theItem.languageCode + "'>" + theItem.languageName + "</option>");
}
catch (error) {
alert(error);
}
});
$(languages.join('')).appendTo("#dpdLanguages").trigger("create");
}
});
here is the json output.
here is the output when only one language:
{"geographyInfo":{"active":"true","countryCode":"US","countryName":"UNITED STATES","instanceID":"1","languageCode":"EN","languageName":"English","regionName":"North America"},"reasonDetails":null,"size":"1","status":"true"}
and in multiple cases
{"geographyInfo":[{"active":"true","countryCode":"CA","countryName":"CANADA","instanceID":"1","languageCode":"EN","languageName":"English","regionName":"North America"},{"active":"true","countryCode":"CA","countryName":"CANADA","instanceID":"1","languageCode":"FR","languageName":"French","regionName":"North America"},{"active":"true","countryCode":"CA","countryName":"CANADA","instanceID":"2","languageCode":"EN","languageName":"English","regionName":"Americas"}, {"active":"true","countryCode":"CA","countryName":"CANADA","instanceID":"2","languageCode":"FR","languageName":"French","regionName":"Americas"}],"reasonDetails":null,"size":"4","status":"true"}
yes udidu, i think thats the case.. but how to solve this?