函数getInfo()读取JSON,它基于传递的键通过简单的串联返回URL。我看到该方法返回一个URL,但是调用方法获取的值未定义。
function getInfo(DebugTool, ServiceName, ELBOrInstance) {
if (DebugTool == "Kibana") {
console.log("Kibana");
if (ELBOrInstance == "ELB") {
$.each( data.ServiceBlock, function( index, serviceblock ) {
if (serviceblock.Service == serviceName) {
console.log("Returning " + encodeURI(data.KibanaELBLink + data.KibanaELBSuffix.replace("ELBNAME", serviceblock.ELBName)));
return encodeURI(data.KibanaELBLink + data.KibanaELBSuffix.replace("ELBNAME", serviceblock.ELBName));
}
});
}
else {
return (data.KibanaInstanceLink + data.KibanaDaemonSuffix.replace("DAEMONNAME", serviceName));
}
}..........
}
console.log显示我需要的正确URL。我将相同的内容返回给调用方法,但实际的返回值为undefined
console.log ("Getting " + getInfo("Kibana", key, "ELB"));
我的脑袋弯了一下,不知道。