Fixed JavaScript doesn't always work when page loads via AJAX

digitalpoint

Well-known member
Affected version
2.1.0
Ran into an issue where a page with a little bit of inline JavaScript (via <xf:js>) wouldn't run if the page was loaded with AJAX, but it would if it wasn't loaded with AJAX. Specifically the inline JavaScript used XF.Element.register() and it didn't seem to get fired.

Not sure if it's intended, but it looks like core.js is firing XF.activate() before it evaluates the inline JavaScript that came from the AJAX response.

JavaScript:
if (!skipActivate)
{
    XF.activate($html);
}

for (var j = 0; j < embeddedScripts.length; j++)
{
    $.globalEval(embeddedScripts[j]);
}

Shouldn't new JavaScript be executed before the new content is "activated"?

Work around is to move that line of JavaScript to an external .js file (then it works as HTML or AJAX page rendering).
 
Thank you for reporting this issue. It has now been resolved and we are aiming to include it in a future XF release (2.1.1).

Change log:
When processing ajax responses, activate HTML elements after executing any inline scripts.
Any changes made as a result of this issue being resolved may not be rolled out here until later.
 
Top Bottom