JHtmlBehavior::keepalive javascript problem #1507

Closed
hispid opened this Issue Aug 31, 2012 · 9 comments

Projects

None yet

6 participants

hispid commented Aug 31, 2012

The original javascript looks like:

    $document = JFactory::getDocument();
    $script = '';
    $script .= 'function keepAlive() {';
    $script .= '    var myAjax = new Request({method: "get", url: "index.php"}).send();';
    $script .= '}';
    $script .= ' window.addEvent("domready", function()';
    $script .= '{ keepAlive.periodical(' . $refreshTime . '); }';
    $script .= ');';

The problem is in url address, used in ajax request (it's not SEF friendly, so when in SEF mode this doesn't work).

To resolve the issue, I used JRoute to make url SEF-friendly:

    $document = JFactory::getDocument();
    $script = '';
    $script .= 'function keepAlive() {';
    $script .= '    var myAjax = new Request({method: "get", url: "'.JRoute::_('index.php').'"}).send();';
    $script .= '}';
    $script .= ' window.addEvent("domready", function()';
    $script .= '{ keepAlive.periodical(' . $refreshTime . '); }';
    $script .= ');';
Contributor
ianmacl commented Aug 31, 2012

On what environments does this fail? I am unable to reproduce here.

hispid commented Aug 31, 2012

Now I'm using version 2.5.6, but this issue seems to be there from 1.6 branch (I'm tired to fix it each time I update joomla).

To reproduce this you're to enable SEF and wait for about 15 minutes (or you may reduce session time to get it faster). Then you should see the javascript error.

In Google Chrome it looks like:

GET http://sitename.org/ru/index.php 404 (Not Found) mootools-core.js:485
c.Request.Class.send mootools-core.js:485
i.extend.$owner mootools-core.js:141
keepAlive management.html:21
(anonymous function) mootools-core.js:84

Contributor
elinw commented Aug 31, 2012

So the environment question means what server and server version are you on, what php version you are on and similar items.
Are you saying it works as expected until your session expires?

hispid commented Aug 31, 2012

Environment:

PHP Built On: FreeBSD buran.lan 8.2-STABLE FreeBSD 8.2-STABLE #4: Tue Dec 27 23:59:59 MSK 2011 root@buran.lan:/usr/obj/usr/src/sys/buran.2011-05-13 amd64
Database Version: 5.3.6-MariaDB-log
Database Collation: utf8_general_ci
PHP Version: 5.3.13
Web Server: nginx/1.2.0
WebServer to PHP Interface: fpm-fcgi
Joomla! Version: Joomla! 2.5.6 Stable [ Ember ] 19-June-2012 14:00 GMT
Joomla! Platform Version: Joomla Platform 11.4.0 Stable [ Brian Kernighan ] 03-Jan-2012 00:00 GMT
User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.83 Safari/537.1

Yes, it works as expected after patch.

hispid commented Aug 31, 2012

The difference is that in original code the request goes to the main page, and after patch the request goes to the current page the user is viewing (because of JRoute using of current option and view variables).

@ghost
ghost commented Aug 31, 2012

In http://sitename.org/ru/index.php where does the ru come from? Is that
the directory your site is in? I tried this on a couple of sites and the
requests load fine.

On Fri, Aug 31, 2012 at 5:56 AM, hispid notifications@github.com wrote:

The difference is that in original code the request goes to the main page,
and after patch the request goes to the current page the user is viewing
(because of JRoute using of current option and view variables).


Reply to this email directly or view it on GitHubhttps://github.com/joomla/joomla-platform/issues/1507#issuecomment-8187392.

hispid commented Sep 1, 2012

This is language, added by SEF engine. Site is multilingual, maybe that is the reason.

@eddieajau eddieajau closed this Apr 5, 2013
clytras commented Feb 13, 2014

I just got this error on a Joomla! 2.5.18 Stable with all extensions updated.

This is a bug and let me explain why.
What this function does is that it calls index.php before session expires to prevent losing data while writing/editing an article.

/**
 * Keep session alive, for example, while editing or creating an article.
 *
 * @return  void
 *
 * @since   11.1
 */

The problem is that when Joomla has SEO urls, for example:
http://mysite.com/products/motorcycles/motard
/products/motorcycles/motard/ is not a real directory and thus it does not contain any index.php file that this function calls by using mootools Request Ajax method. So, in order to do it right, the php function has to route index.php to site root, for instance http://mysite.com/index.php which is what JRoute::_('index.php') does instead of just having "index.php". So for me this is a bug that I have to correct every time I install a new Joomla site or doing a core update.

I just tried executing the bellow code
var myAjax = new Request({method: "get", url: "index.php"}).send(); which is there, inside session alive

Yes indeed it sends the request to an inner index.php path. But in my case it worked since the inner depth was 2 and yet the request URL was like /index.php/index.php, where index.php was there multiple times.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment