[英]Javascript jQuery closing bracket error
I want my output to be in order like: 我希望我的输出像这样:
console.log("1st 1:", y1, y2, y3, y4);
console.log("1st 2:", y1, y2, y3, y4);
console.log("2nd 1:", y1, y2, y3, y4);
console.log("2nd 2:", y1, y2, y3, y4);
console.log("3rd:", y1, y2, y3, y4);
But I am getting Uncaught TypeError: undefined is not a function
in the done
statement. 但是我收到了Uncaught TypeError: undefined is not a function
在done
语句中Uncaught TypeError: undefined is not a function
。
And only be able to see: 而且只能看到:
1st 1: 5 5 5 5
1st 2: 8 30 236 365
I can't find anything wrong with this code: 我找不到此代码有什么问题:
data: (
function() {
// Test
y1 = 5,
y2 = 5,
y3 = 5,
y4 = 5;
// Ajax is asynchronous
function doRun() {
$.ajax({
type: "GET",
url: "/getTest",
success: function(data) {
console.log("1st 1:", y1, y2, y3, y4);
y1 = data.V1;
y2 = data.V2;
y3 = data.V3;
y4 = data.V4;
console.log("1st 2:", y1, y2, y3, y4);
}
});
return doRun;
};
doRun().done(function() {
console.log("2nd 1", y1, y2, y3, y4);
}).fail(function() {
console.log("2nd 2");
});
var data = [],
time = (new Date()).getTime(),
i;
for (i = -10; i <= 0; i++) {
console.log("3rd:", y1, y2, y3, y4);
data.push({
x: time + i * 10,
y: 0
});
}
return data;
}()
)
What should I do fix this problem and printing everything in order? 我应该如何解决此问题并按顺序打印所有内容?
function doRun() {
return $.ajax({
type: "GET",
url: "/getTest",
success: function(data) {
console.log("1st 1:", y1, y2, y3, y4);
y1 = data.V1;
y2 = data.V2;
y3 = data.V3;
y4 = data.V4;
console.log("1st 2:", y1, y2, y3, y4);
}
});
};
You were returning the wrong thing. 您返回的是错误的内容。 You returned doRun
-- the same function that was called. 您返回了doRun
-与调用的函数相同。 doRun
does not have a done
property. doRun
没有done
属性。 You meant to return the promise from $.ajax
. 您打算从$.ajax
退还诺言。
Your call to doRun() is returning the doRun function object. 您对doRun()的调用返回了doRun函数对象。 Does that actually have a done() method defined on it? 实际上是否定义了done()方法? I'm guessing not. 我猜不是。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.