trying to display data only after variables have been set.
$("document").ready(function () {
function setdata() {
var mydata = '123';
};
$.when(setdata()).done(function () {
$(".content").text(mydata);
});
});
You don't need $.when in this case since you aren't actually passing it a promise object.
$("document").ready(function () {
var mydata;
function setdata() {
mydata = '123';
};
setdata();
$(".content").text(mydata);
});
Is setdata doing more than what you are showing in your question? I'm guessing it does an ajax request, in which case it should look like this:
$("document").ready(function () {
function setdata() {
return $.ajax(ajaxOptions);
};
setdata().done(function(mydata){
$(".content").text(mydata);
});
});
$.when().ready()handler.setdatadoes not return a promise object, why is it being passed to$.when? the$.whenwill return a resolved promise object if you don't give it a promise object and the.donewill be called immediately since it is already resolved. Sure, it will work, but it is pointless.