I have the following function which works fine when tied to an onClick() event.. However if the event is fired onReady() it fails to do it job.. Adding an alert() at any point in the method allows it to work fine.. So I know it’s related to an Asynchronous AJAX request. I just haven’t had any luck successfully adding deferred or callback logic.. not sure how to approach it.
Does a simple way exist to improve the method? I’m ultimately calling this method onOpen() for a jQueryUI Dialog.. But the dialog fires and is empty..
function performElqLookups(formName) {
var elqTracker = new jQuery.elq(459);
//first do the visitor lookup
var visitorLookup = 'ba109a0a75294aed95ca72b0bc3b345d';
elqTracker.getData({ key: visitorLookup, lookup: "", success: function() {
//then check for an email address on the visitor record and do a contact data lookup if there is one
if (typeof GetElqContentPersonalizationValue == "function") {
var email = GetElqContentPersonalizationValue("V_ElqEmailAddress");
if (email != "") {
var contactLookup = 'c7e9dd7150464162af6fe1cf471627e5';
elqTracker.getData({ key: contactLookup, lookup: "<C_EmailAddress>" + email + "</C_EmailAddress>", success: function() {
populateForm(formName);
trackPage().done(function( guid ) {
$('#elqCustomerGUID').val(guid);
});
}});
}
}
}});
}
you can set Ajax to synchronous by passing
async:falseto any ajax calls such asget() load()andajax()also, remember that you should always wrap your code with
$(function(){..code in here..})because this is shorthand for document.onReady