I am so so stuck with this. I have a functionA which I want to call functionB (my API call) and have it return the results of the data. The API is a "queue" and "get" type. It should run like this:
- Run API query with "queue" type
- Collect returned reportID
- Run API query with "get" type and reportID
- Collect data into myfunction
This is my current code:
function myfunction() {
var ref;
var type = "queue";
var metric = "pageviews";
var post = getReport(ref, type, metric);
post.done(function (r) {
console.log (r);
}
);
}
function getReport(ref, type, metric) {
return $.ajax({
url: "report.php",
dataType: 'json',
data: {
ref: ref,
type: type,
metric: metric
}
});
}
This works fine. However I can't get the loop working correctly for the second part of my query. This is what I tried:
function myfunction() {
var ref;
var type = "queue";
var metric = "pageviews";
var post = getReport(ref, type, metric);
post.done(function (r) {
if (type == "queue")
{
myfunction(r.reportID,"get");
}
else if (type == "get")
{
console.log(r);
}
);
}
I keep overwriting the value of type which seems to cause an infinite loop.
typefromqueuetogetmyfunctioncall in there? And when you domyfunction(r.reportID,"get");the"get"is simply ignored completely. Not only hasmyfuncitonno arguments, even if it did, you're shadowingtypeby hardcoding it to "queue"-