[英]Argument is returning empty value on console.log
I am trying to pass an argument down the tree to the successResponse errorResponse functions and display the value in the console before I do any work with it. 我正在尝试将树参数传递给successResponse errorResponse函数,并在进行任何操作之前在控制台中显示该值。
Currently I am getting an empty value in the console so there must be something missing in my code. 当前,我在控制台中得到一个空值,因此我的代码中肯定缺少某些内容。 I am thinking its a return statement but when I attempt this I get no result.
我在想它是一个return语句,但是当我尝试这样做时,我没有任何结果。
Any help would be greatly appreciated. 任何帮助将不胜感激。
The console.log is below. console.log在下面。
successResponse: function (getSel) {
requestResponses.errorCode = false;
requestResponses.redLight.removeClass(requestResponses.redBright);
requestResponses.greenLight.addClass(requestResponses.greenBright);
console.log(getSel);
},
Here is the full version of my code 这是我的代码的完整版本
var requestResponses = {
greenLight: $('.cp_trafficLight_Light--greenDimmed'),
redLight: $('.cp_trafficLight_Light--redDimmed'),
greenBright: 'cp_trafficLight_Light--greenBright',
redBright: 'cp_trafficLight_Light--redBright',
settings: {
flashError: 400,
requestTime: 10000
},
init: function (url, getSel) {
requestResponses.url = url;
requestResponses.getResponse(requestResponses.url, getSel);
setInterval(function () {
if (requestResponses.errorCode === true) {
requestResponses.redLight.toggleClass(requestResponses.redBright);
}
}, requestResponses.settings.flashError);
},
successResponse: function (getSel) {
requestResponses.errorCode = false;
requestResponses.redLight.removeClass(requestResponses.redBright);
requestResponses.greenLight.addClass(requestResponses.greenBright);
console.log(getSel);
},
errorResponse: function () {
requestResponses.greenLight.removeClass(requestResponses.greenBright);
},
getResponse: function (serverURL, getSel) {
$.ajax(serverURL, {
success: function (getSel) {
requestResponses.errorCode = false;
requestResponses.successResponse(getSel);
},
error: function () {
requestResponses.errorCode = true;
requestResponses.errorResponse();
},
complete: function () {
setTimeout(function () {
requestResponses.getResponse(requestResponses.url);
}, requestResponses.settings.requestTime);
}
});
},
errorCode: false
}
requestResponses.init('/status');
Appreciate any help. 感谢任何帮助。
Your code looks fine. 您的代码看起来不错。 Make sure that the server actually responds with data.
确保服务器实际响应数据。 The problem is most likely on back-end.
该问题最有可能在后端。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.