Rich-text Reply

Optimizely doesn't recognize ajaxComplete()

asebold 03-17-15

Optimizely doesn't recognize ajaxComplete()

I am trying to set up an experiement on an angular app. Every time the app refreshes content on the page I would like my script to be applied. I tried to use $(document).ajaxComplete(function() { ...stuff I want to do... });  in the code editor, but optimizely keeps popping up with this error: 

 

Error evaluating variation javascript:
TypeError: undefined is not a function (line 1, col 13)

 

experiement id is 2667640622 if that helps. 

 

Thanks! 

Level 2

Re: Optimizely doesn't recognize ajaxComplete()

[ Edited ]

Hi there,

Thanks for your post!

Optimizely's trimmed version of jQuery 1.6.4 does not support the ajaxComplete() function, which is why you're seeing that error message. If you'd like to use ajaxComplete(), you'll have to change your project settings to include the full version of jQuery 1.6.4 or opt to use your own jQuery library that includes the ajaxComplete() method. For more information about how to change your project settings, here is a handy knowledge based article --> https://help.optimizely.com/hc/en-us/articles/202480860-Project-Settings#jquery_settings

However, with single page apps, it's preferable to use Optimizely's Manual or Conditional activation. Here's more information about why that's so and also how to set it up properly.
https://help.optimizely.com/hc/en-us/articles/200040225-Activating-an-Optimizely-Experiment-dynamica...

Finally, here's an Optiverse discussion where our community members give their two cents about how to use Optimizely with AngularJS!
https://community.optimizely.com/t5/Using-Optimizely/Optimizely-and-AngularJS/td-p/490

Hope this helps! Let me know how it goes Smiley Happy

Cheers,

Amy Herbertson
Customer Success
asebold 03-18-15
 

Re: Optimizely doesn't recognize ajaxComplete()

I was able to set up a new project with the full version of jquery enabled, but my test still isn't working. I don't think ajaxComplete() is firing on every ajax call. Not sure what I'm doing wrong here. The experiment is running on this page if you can take a look: http://www.spiritcruises.com/philadelphia/search?timeOfDay=Any&metro=Philadelphia&startDate=03%2F18%...

If the test is working, there should be a section called Inclusive Price next to Base Price.
Experiment id is 2669990507.

Level 2
asebold 03-19-15
 

Re: Optimizely doesn't recognize ajaxComplete()

I used ajaxStop() and it seems to be working now. Thanks!

Level 2

Re: Optimizely doesn't recognize ajaxComplete()

Awesome! Glad to hear it Smiley Happy
Amy Herbertson
Customer Success
kmaughan 03-15-17
 

Re: Optimizely doesn't recognize ajaxComplete()

window.$(document).ajaxSuccess(function(event, xhr, settings){...//do stuff}); was working for me within variation code however, not working when used within context of a conditional activation callback function. Waiting for DOM ready before attaching the listener to window.$(document) resolved this issue for me

 

Example: 
function(activate, options) {
  $(function() {
    window.$(document).ajaxSuccess(function(event,xhr,settings,data){
      if (settings.url.indexOf('/some url/') > -1 && !options.isActive) {
        //do stuff, then
        activate();
      }
    });
  });
}

kmaughan
Level 2