我是一名编程训练营的学生,在ajax调用运行时延迟函数调用时遇到了问题-我知道这可以通过Promise来解决,但是我还没有达到这个水平。我当时在想,我可以使用setTimeInterval来延迟ajax调用运行时调用该函数的时间,但尝试这样做却无法做到。我的代码在下面列出-任何帮助将不胜感激。当ajax运行时,totalPrice函数返回未定义的值,并且在ajax数据可用之后,我需要运行该函数。 谢谢,在耳朵编码器后面弄湿了
$.ajax({
url: queryURL,
method: "GET",
}).done(function (results) {
console.log(results);
console.log("Recipe Button Clicked!")
//recipes is results.hits which is an array of recipes
var recipes = results.hits;
for (var i = 0; i < 3; i++) {
console.log('STATEMENT:' + getTotalPrice(recipes[i]));
console.log(typeof totalPrice[i]);