[ticket/12099] Improve code for relative path when AJAX is used

PHPBB3-12099