Rich-text Reply

ajaxComplete doesn't work

Linnea_Vendre 01-09-17

ajaxComplete doesn't work

Hi!

 

I’ve created an experiment and included an ajaxStart function and according to this page: 

 

https://help.optimizely.com/Set_Up_Optimizely/Project_Settings_JavaScript_and_jQuery_settings

 

ajaxComplete, ajaxStart, ajaxStop and so on should work if I’ve included the full jQuery 1.11.3, and I have, but it doesn’t work.

 

How come it doesn’t work?

 

Experiment ID: 7972791566

RyanC 01-09-17
 

Re: ajaxComplete doesn't work

Use the prefix optimizely before the jQuery $

e.g.
optimizely.$( document ).ajaxStart(function()................
Ryan
------------------------------------------------
The best solution is the simplest.

https://www.linkedin.com/in/ryan-camilleri
http://midnightknights.com
Experimentation Hero

Re: ajaxComplete doesn't work

Thank you for the answer. It still doesn't work though Smiley Sad
RyanC 01-10-17
 

Re: ajaxComplete doesn't work

Sounds like an Optimizely tech needs to look into your code/setup.
Ryan
------------------------------------------------
The best solution is the simplest.

https://www.linkedin.com/in/ryan-camilleri
http://midnightknights.com
Experimentation Hero

Re: ajaxComplete doesn't work

So it seems.
It's not complicated code at all, so I really don't understand why ajaxComplete doesn't work...
RyanC 01-10-17
 

Re: ajaxComplete doesn't work

Trying placing your code directly in the browser's console. (Google Chrome - F12) This way you will be taking out Optimizely out of the equation and confirming that your code works.
Ryan
------------------------------------------------
The best solution is the simplest.

https://www.linkedin.com/in/ryan-camilleri
http://midnightknights.com
Experimentation Hero

Re: ajaxComplete doesn't work

I have done that from the get go to check if the code works and it all works fine when i do that. Even the ajaxStart part.
RyanC 01-10-17
 

Re: ajaxComplete doesn't work

Ok then it sounds like Optimizely fires the code when something is not yet present on your page. Try using conditional activation to launch your experiment when the objects you need are present.

Read: https://help.optimizely.com/Build_Campaigns_and_Experiments/Activation_Mode%3A_Activating_an_experim...
Ryan
------------------------------------------------
The best solution is the simplest.

https://www.linkedin.com/in/ryan-camilleri
http://midnightknights.com
Experimentation Hero

Re: ajaxComplete doesn't work

That might work, unfortunately the client doesn't want to pay for the Enterprise plan which is required for that functionality.
RyanC 01-10-17
 

Re: ajaxComplete doesn't work

No need, use setinterval in your code.
Ryan
------------------------------------------------
The best solution is the simplest.

https://www.linkedin.com/in/ryan-camilleri
http://midnightknights.com
Experimentation Hero

Re: ajaxComplete doesn't work

Do you mean like this:

setInterval(function(){

$(document).ajaxStart(function() {

// Code....

});

}, 100);

?
RyanC 01-10-17
 

Re: ajaxComplete doesn't work

Almost .... Put an if condition to check for the element the ajax relies on and stop the interval once it has been satisfied.
Ryan
------------------------------------------------
The best solution is the simplest.

https://www.linkedin.com/in/ryan-camilleri
http://midnightknights.com
Experimentation Hero

Re: ajaxComplete doesn't work

That doesn't work either. Console.logged within the setintervall so that I was sure the code inside is read at a later stage, but the ajax function still doesn't trigger. It's as if none of the ajaxComplete / Start / Stop and so on exists.