I have the following function that takes this frequency parameter and calls the api, but the parameter frequency is not defined inside the SUCCESS callback and I need it. How to pass that parameter to my callback?
init : function(frequency) {
$.ajax({
url: 'api/v1/dashboard',
type: "GET",
dataType: "json",
data : {username : "demo",frequency : frequency},
success: function(data) {
dashboard_hander.set_data(data.dashboard);
//here frequency is undefined
}
});
},
EDIT 2 =====
It works by defining parameters = {username : “demo”,frequency : frequency};
outside of the $.ajax and passing as data object, or defining frequency in a higher scope, like:
var dashboard_hander = {
frequency : "",
init : function(frequency) {
this.frequency = frequency;
...
}
}
Just define it at a higher scope.