Rich-text Reply
Highlighted

(re)activating on ajaxComplete

RaduJudele 06-01-15

(re)activating on ajaxComplete

Hi!

Could you please help us regarding the following issue?

 

We are trying to change some css attributes on elements that are loaded using an Ajax request. (Load more button)

 

Inside the code editor we have:

$( document ).ready(function() {
  window.$( document ).ajaxComplete(function(event,xhr,options) {
    window.optimizely = window.optimizely || [];
    window.optimizely.push(["activate"]);
    console.log('AJAX-COMPLETE-OK');
  });
});

The elements that are already in page are changed ok, but after the Ajax request, the message 'AJAX-COMPLETE-OK' is showed in console, but nothing changes on the new elements in page.

 

We have tried this using both Immediate and Manual activation settings and using preview / live, but it doesn't work.

 

Thank you!

Re: (re)activating on ajaxComplete

[ Edited ]

Hi there,

Could you give us an experiment ID and a URL to look at? Also some screenshots would be very helpful!

I'm shooting in the dark until I get more information, but just wanted to note, that I often try using a setInterval function when AjaxComplete doesn't work as I'd expect. (See below)

window.myInterval = setInterval(function() {
if ($('[ELEMENT_YOU_ARE_CHECKING_TO_EXIST]').length > 0) {
//VARIATION CODE EXECUTING CHANGES
clearInterval(window.myInterval);
}
}, 50);



Looking forward to hearing back from you!

Best,

Amy Herbertson
Customer Success
JDahlinANF 06-02-15
 

Re: (re)activating on ajaxComplete

Depending on what the AJAX is doing (and how it handles the success event) ajaxComplete could be called before the response has been placed into the DOM.