joomla/joomla-cms — pull request #4904 by maxvalentini77 (2014-10-23 15:33:32+00:00)
Title: Fix behavior keepalive

### I found three issues:
1: In some cases, call an invalid url, resulting in a response with code 404. (still refresh the session)
2: Update the article hits counter.
3: Work in different ways with "Search Engine Friendly URLs" enabled or disabled.

### How to reproduce number 1
- Enable "Search Engine Friendly URLs"
- Set "Session Lifetime" to 1 (not required but useful to test faster!)
- Create a menu of type "Menu Heading" and call it "heading"
- Create a menu that point to an article and add it as child of "heading"
- Create a Login module and put it some where in the page (add the "behavior.keepalive")
- Use the article menu (you will be redirected to a page with an URL like "www.host.net/index.php/heading/article")
- Wait some "Session Lifetime" minutes and an ajax call to the URL "www.host.net/index.php/heading/" will be executed but ends with a 404 error

The session is refreshed but it isn't nice to generate a 404 error that, for example, ends up in the apache logs.

### How to reproduce number 2
- Set "Session Lifetime" to 1 (not required but useful to test faster!)
- Create a menu that point to an article and set it as default
- Create a Login module and put it some where in the page (add the "behavior.keepalive")
- Go to the homepage of the site, the article will be displayed with a counter hits = C
- Wait some "Session Lifetime" minutes and an ajax call to the homepage will be executed (increasing the hits counter)
- Refresh the page

The counter was increased by 1+X where X is the number of ajax calls.

### How to reproduce number 3
- Disable "Search Engine Friendly URLs"
- Set "Session Lifetime" to 1 (not required but useful to test faster!)
- Create a menu of type "Menu Heading" and call it "heading"
- Create a menu that point to an article and add it as child of "heading"
- Create a Login module and put it some where in the page (add the "behavior.keepalive")
- Use the article menu (you will be redirected to a page with an URL like "www.host.net/index.php?option=com_content&view=article&id=12&Itemid=160")
- Wait some "Session Lifetime" minutes and an ajax call to the URL "www.host.net/" will be executed.

This is the same procedure to reproduce number 1 but ends with a different behavior that, if the homepage display an article, generate the same issue of number 2.
(This because the homepage of the site has been called.)

### Proposed solution
I modified the URL of the ajax call from "./" to:
```php
JRoute::_("index.php?option=com_ajax&format=json", false)
```
This call refresh the session without generate any html and/or call model methods that can lead to unexpected/unwanted behaviors (for example in an increased article hits counter).
This call is available on both site and administrator applications.

To test it in the administrator application (for example) go to the edit category page that include the "behavior.keepalive" and wait for the ajax call.