i have more than 3 functions and i want to execute the first function and when it finish i will execute the second one and so on . this is the code im trying to use but it execute all functions in the some time .
var categoriesReady = $.Deferred();
var linksReady = $.Deferred();
var dataReady = $.Deferred();
function getCategories(){
$.getJSON(serviceURL + 'get_categories', function(data) {
cats = data.categories;
$.each(cats, function(index, cat) {
$("#menuIcons").append('<li><a data-ajax="false" href="ca.html?id='+cat.id+'">'+cat.title+'</a></li>');
});
});
categoriesReady.resolve();
}
function getLinks(){
$.getJSON(serviceURL + 'get_links', function(data) {
links = data.links;
$.each(links, function(index, link) {
$("#menuIcons").append('<li><a data-ajax="false" href="link.html?id='+link.id+'">'+link.title+'</a></li>');
});
});
linksReady.resolve();
}
function getLinks(){
$.getJSON(serviceURL + 'get_links', function(data) {
cats = data.categories;
$.each(cats, function(index, cat) {
$("#menuIcons").append('<li><a data-ajax="false" href="ca.html?id='+cat.id+'">'+cat.title+'</a></li>');
});
});
linksReady.resolve();
}
function getData(){
$.getJSON(serviceURL + 'get_links', function(data) {
posts = data.posts;
$.each(cats, function(index, post) {
$("#menuIcons").append('A : '+post.content);
});
});
dataReady.resolve();
}
function init(){
$("body").append("3 function are done!");
}
$.when(getCategories(),getLinks(),getData()).then(init);
whats the problem ?