I am creating a jquery plugin. I want to get data from back end and send as options to the plugin.
function getData(){
$.when(http_get('../list/')).then(function(response){
students = response;
return students;
console.log(response);
}, function(response){
console.log('get failed');
})
}
$('#element').pluginSmart({
data: getData()
});
Here I am getting the data from backend but it is not assigned to the data option of the plugin.
I know the data is assigned before the ajax returns. How to wait till the ajax returns and then assign?
I want to keep it plugin initialization simple. otherwise I would have initiated the plugin inside the then function.