I have the following javascript file called script.js
with a jQuery function:
function getData(a, b) {
var d = [];
while (a <= b)
{
$.ajax({
url: "someurl",
dataType: 'json',
success: function (data) {
d.push(data.rates);
},
error: function (err) {
console.log(err);
}
});
a+=1;
}
$(document).ajaxStop(function () {
console.log("AJAX STOP");
return d;
}); }
Explanation:
I fill the array d
in a while loop with some information I get as a response from server someurl
. I would like to pass this array to my controller called MainController.js
. How do I do this? I would like to have a property in my controller, for example $scope.dataFromAjax, and it has to be equal to the final form of array d
from ajax().
(something like $scope.dataFromAjax = d
).
Thank you.