Author Topic: AJAX not working on adding products to cart  (Read 15542 times)

vanarebane

  • Beginner
  • *
  • Posts: 2
AJAX not working on adding products to cart
« on: December 19, 2009, 21:04:55 pm »
Hello,

I have this problem that my Virtue Mart 1.1.3 is not adding products to cart with AJAX.

The problem seems to appear only in a fresh browser that has not yet logged in or registered. When in this browser is clicked the "add to cart" button nothing happens. If I log in for once it starts to work as it should even if I log out and delete the whole history. It seems as like there is something loaded to cache when logged in and works even when logged out after that.

So far FF, Chrome and Safari seem to be affected. IE works fine.

I also see that there is "el is null" in error console but so far I have not figured out where is it coming.

You can find the shop here: http://www.minuhelmed.ee

Your help is most appreciated. Thanks!

jenkinhill

  • UK Web Developer & Consultant
  • Global Moderator
  • Super Hero
  • *
  • Posts: 27495
  • Always on vacation
    • Jenkin Hill Internet
Re: AJAX not working on adding products to cart
« Reply #1 on: December 21, 2009, 11:22:54 am »
Worked first time for me. Maybe you have fixed it already?
Kelvyn

Jenkin Hill Internet,
Lowestoft, Suffolk, UK

Unsolicited PMs/emails will be ignored.

Please mention your VirtueMart, Joomla and PHP versions when asking a question in this forum

Currently using VM 3.6.1.10121 on Joomla 3.9.11 PHP 7.0.33
Testing 3.6.1.10129 on Joomla 3.9.11

vanarebane

  • Beginner
  • *
  • Posts: 2
Re: AJAX not working on adding products to cart
« Reply #2 on: December 30, 2009, 16:04:41 pm »
I haven't had time to work on this so now I'm back on this.

I compared the working site and non-working site and discovered the only difference between them is domain name. So if the site is http://minuhelmed.ee it does not work. If it's changed to http://www.minuhelmed.ee the AJAX starts to work.

Apparently the missing "www." was the cause.

So now I figured that I build simple javascript to detect if the site is loaded without "www." in the domain address it will redirect the page to same page with "www." on load.

Thanks for response. Hope that this topic could be used to fix some undiscovered bug or something.

jenkinhill

  • UK Web Developer & Consultant
  • Global Moderator
  • Super Hero
  • *
  • Posts: 27495
  • Always on vacation
    • Jenkin Hill Internet
Re: AJAX not working on adding products to cart
« Reply #3 on: December 31, 2009, 11:41:54 am »
Thanks for response. Hope that this topic could be used to fix some undiscovered bug or something.

This issue has been long known for some server/site setups. Our advice is to use .htaccess in the site root to force the use of www.
Kelvyn

Jenkin Hill Internet,
Lowestoft, Suffolk, UK

Unsolicited PMs/emails will be ignored.

Please mention your VirtueMart, Joomla and PHP versions when asking a question in this forum

Currently using VM 3.6.1.10121 on Joomla 3.9.11 PHP 7.0.33
Testing 3.6.1.10129 on Joomla 3.9.11

Forrest

  • Full Member
  • ***
  • Posts: 1972
  • Me and my baby
    • Web Developer
Re: AJAX not working on adding products to cart
« Reply #4 on: January 06, 2010, 11:11:50 am »
Add this code at bottom of .htaccess, for both http, https:


###### Added by Forrest to insure AJAX cart works by force of www
#
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS} =on
RewriteRule .* https://www.%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS} !=on
RewriteRule .* http://www.%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
#
########## End - Addition by Forrest


If you want to specify ONE domain or BY domain instead use this:
Note: make sure you repalce "YOURDOMAINHERE" with your domain name without www.

###### Added by Forrest to insure AJAX cart works by force of www
#
RewriteCond %{HTTP_HOST} ^YOURDOMAINHERE\.com
RewriteCond %{HTTPS} =on
RewriteRule .* https://www.%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^YOURDOMAINHERE\.com
RewriteCond %{HTTPS} !=on
RewriteRule .* http://www.%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
#
########## End - Addition by Forrest


raygun

  • Beginner
  • *
  • Posts: 4
Re: AJAX not working on adding products to cart
« Reply #5 on: January 29, 2010, 02:36:09 am »
Code: [Select]
###### Added by Forrest to insure AJAX cart works by force of www
#
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS} =on
RewriteRule .* https://www.%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS} !=on
RewriteRule .* http://www.%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
#
########## End - Addition by Forrest

I have the same problem and the above code really works for me.
Thanks Forrest!

stenaxel

  • Beginner
  • *
  • Posts: 2
Re: AJAX not working on adding products to cart
« Reply #6 on: March 05, 2010, 10:50:45 am »
I have done as above written but the website disappeared completely.

If I delete the .htaccess file I can see the website again but the shop does not work.

Forrest

  • Full Member
  • ***
  • Posts: 1972
  • Me and my baby
    • Web Developer
Re: AJAX not working on adding products to cart
« Reply #7 on: March 05, 2010, 10:55:00 am »
1. You need to make sure mod_rewrite is enabled in .htacess.

2. Please read about using .htaccess before using.

greenparrot

  • Beginner
  • *
  • Posts: 32
Re: AJAX not working on adding products to cart
« Reply #8 on: March 24, 2010, 12:29:15 pm »
Hi

Not sure if i should be posting to a solved thread but i'm having trouble getting the forced use of www through htaccess to work. Attached is my htaccess file, i know rules from htaccess are being used as SEF works fine.

I also need to Rewrite the url example.co.uk to example.com, and of course www.example.co.uk to www.example.com

To keep the site working whilst sorting this i have set
Code: [Select]
useAjaxCartActions=0 in theme.config.php

Thanks for any help

Roy

[attachment cleanup by admin]

Forrest

  • Full Member
  • ***
  • Posts: 1972
  • Me and my baby
    • Web Developer
Re: AJAX not working on adding products to cart
« Reply #9 on: March 24, 2010, 18:45:56 pm »
.htaccess is often cached by your host. You may need to give this ample time to start working (cache is flushed). How much time depends on your host/server, and you may need to call them to ask.

ex3mist

  • Jr. Member
  • **
  • Posts: 71
Re: AJAX not working on adding products to cart
« Reply #10 on: April 13, 2010, 12:34:28 pm »
.htaccess is often cached by your host. You may need to give this ample time to start working (cache is flushed). How much time depends on your host/server, and you may need to call them to ask.

I tryed adding the following code to the .htaccess file:

###### Added by Forrest to insure AJAX cart works by force of www
#
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS} =on
RewriteRule .* https://www.%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS} !=on
RewriteRule .* http://www.%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
#
########## End - Addition by Forrest

Nothing changed even after waiting for some time to pass. I tryed then replacing this code:

########## Begin - Joomla! core SEF Section
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$  [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
#
########## End - Joomla! core SEF Section

with yours:

###### Added by Forrest to insure AJAX cart works by force of www
#
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS} =on
RewriteRule .* https://www.%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS} !=on
RewriteRule .* http://www.%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
#
########## End - Addition by Forrest

and it began showing "Page not found" message. However I turned the Apache mod_rewrite off and it worked. Why is that happening?
Is this what I should do? As far as I understood I need to add your code to the file without deleting the existing one, needn't I? Also, when I want to access VM in the backend I have to login second time.
Can you please give me some advice what should I do to fix this?

Forrest

  • Full Member
  • ***
  • Posts: 1972
  • Me and my baby
    • Web Developer
Re: AJAX not working on adding products to cart
« Reply #11 on: April 13, 2010, 19:10:28 pm »
You do not want to over-write my code with that other code. That other code is a separate function of mod_rewrite, specifically for page extension naming convention.

If it's not working, then maybe your host doesn't support mod_rewrite. Call you hosting provider.

ex3mist

  • Jr. Member
  • **
  • Posts: 71
Re: AJAX not working on adding products to cart
« Reply #12 on: April 13, 2010, 19:26:56 pm »
There is another thing I found out - the URL appears in the browser without "www". When I insert "www" and refresh, the "Add to cart" works perfect. The problem is that I tryed botn samples of the code given by you and none of them worked...
Any suggestions, please?

Forrest

  • Full Member
  • ***
  • Posts: 1972
  • Me and my baby
    • Web Developer
Re: AJAX not working on adding products to cart
« Reply #13 on: April 13, 2010, 19:29:18 pm »
That is the point to the .htaccess addition. It should add the www to the URL. But if it is not, then at this point I suggest to CALL YOUR HOST... make sure they support mod_rewrite.

ex3mist

  • Jr. Member
  • **
  • Posts: 71
Re: AJAX not working on adding products to cart
« Reply #14 on: April 24, 2010, 11:39:59 am »
The issue was solved after placing your code directly after RewriteEngine on. Thanks a lot!