I need to wait to run a function until I have a cookie. The setting of the cookie is out of my hands. I'm using the jQuery cookie plugin to retrieve the cookie.
I think the cookie is set after the following is executed:
$.ajax({
url: '//munchkin.marketo.net/munchkin.js',
dataType: 'script',
cache: true,
success: function() {
Munchkin.init('XXX-XXX-XXX');
}
})
On server A, it was enough to place the function call inside the success parameter.
On server B, the cookie is undefined at the time that the "success" function is executed. I also tried the following on server B:
var post = $.ajax({
url: '//munchkin.marketo.net/munchkin.js',
dataType: 'script',
cache: true,
success: function() {
Munchkin.init('XXX-XXX-XXX');
}
});
post.done(function(p){
makeLeadCall($.cookie('_mkto_trk'));
});
How can I wait until the cookie has a value before executing the function?