I am trying to do some AJAX call using $.when
and $.then
functions. I am using these functions to fill a template
and so , in the meanwhile , I want to fill the form that I will fill with some message like
"loading data.. please wait"
I found out that there is a progress
functions but it works only with notify
. I searched through the community and I noticed that it is used with the promise
call. I did not really get the meaning of promise
and how deferred objects are working in my script.
This is my script :
$.when(e.get_info('get_utente'))
}).then(function(data){
$('#username').val(data.username);
$('#email').val(data.email);
})
I would like to insert progress beetween this two calls. Sorry if there's some misunderstanding , but 'till now I was using ASYNC : false
, and after i noticed that is a really bad idea I found out deferred objects , but i dindn't get at all it's logic
The progress callback doesn't really apply to ajax requests at this time.
Instead, do your "loading data.. please wait" message before $.when
.
Also, you don't need $.when
at all, just do
$("#loading").show();
e.get_info('get_utente').done(function(data){
$("#loading").hide();
$('#username').val(data.username);
$('#email').val(data.email);
});
$.when
is only needed if you need to run something when 2 or more promise objects are complete. For a single promise object, it is not needed.