[英]Error: The key is invalid JQuery syntax because it is missing a closing bracket
[英]Javascript jQuery closing bracket error
我希望我的輸出像這樣:
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);
但是我收到了Uncaught TypeError: undefined is not a function
在done
語句中Uncaught TypeError: undefined is not a function
。
而且只能看到:
1st 1: 5 5 5 5
1st 2: 8 30 236 365
我找不到此代碼有什么問題:
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;
}()
)
我應該如何解決此問題並按順序打印所有內容?
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);
}
});
};
您返回的是錯誤的內容。 您返回了doRun
-與調用的函數相同。 doRun
沒有done
屬性。 您打算從$.ajax
退還諾言。
您對doRun()的調用返回了doRun函數對象。 實際上是否定義了done()方法? 我猜不是。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.