VirtueMart Forum

VirtueMart 1.1.x [ Old version - no longer supported ] => Questions VM 1.1 ( the only active board for the old version) => Topic started by: vanarebane on December 19, 2009, 21:04:55 pm

Title: AJAX not working on adding products to cart
Post by: vanarebane 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!
Title: Re: AJAX not working on adding products to cart
Post by: jenkinhill on December 21, 2009, 11:22:54 am
Worked first time for me. Maybe you have fixed it already?
Title: Re: AJAX not working on adding products to cart
Post by: vanarebane 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.
Title: Re: AJAX not working on adding products to cart
Post by: jenkinhill 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.
Title: Re: AJAX not working on adding products to cart
Post by: Forrest 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

Title: Re: AJAX not working on adding products to cart
Post by: raygun 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!
Title: Re: AJAX not working on adding products to cart
Post by: stenaxel 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.
Title: Re: AJAX not working on adding products to cart
Post by: Forrest 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.
Title: Re: AJAX not working on adding products to cart
Post by: greenparrot 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]
Title: Re: AJAX not working on adding products to cart
Post by: Forrest 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.
Title: Re: AJAX not working on adding products to cart
Post by: ex3mist 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?
Title: Re: AJAX not working on adding products to cart
Post by: Forrest 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.
Title: Re: AJAX not working on adding products to cart
Post by: ex3mist 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?
Title: Re: AJAX not working on adding products to cart
Post by: Forrest 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.
Title: Re: AJAX not working on adding products to cart
Post by: ex3mist on April 24, 2010, 11:39:59 am
The issue was solved after placing your code directly after RewriteEngine on. Thanks a lot!
Title: Re: AJAX not working on adding products to cart
Post by: Buildacomputer on July 08, 2010, 03:13:16 am
Hello,

I'm having the same issue. When i place the code at the end of my .htaccess file it doesn't work for the 301 redirect. but when i move it up ahead of everything right under RewriteEngine_on the redirect works but not my cart gives a 500 error message. Please let me know what you think. apache rewrite in joomla is off.

Redirect not working but cart working in www.

##
# @version $Id: htaccess.txt 13415 2009-11-03 15:53:25Z ian $
# @package Joomla
# @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
# @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
# Joomla! is Free Software
##

#####################################################
#  READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE
#
# The line just below this section: 'Options +FollowSymLinks' may cause problems
# with some server configurations.  It is required for use of mod_rewrite, but may already
# be set by your server administrator in a way that dissallows changing it in
# your .htaccess file.  If using it causes your server to error out, comment it out (add # to
# beginning of line), reload your site in your browser and test your sef url's.  If they work,
# it has been set by your server administrator and you do not need it set here.
#
#####################################################

##  Can be commented out if causes errors, see notes above.
Options +FollowSymLinks

#
#  mod_rewrite in use

RewriteEngine On

########## Begin - Rewrite rules to block out some common exploits
## If you experience problems on your site block out the operations listed below
## This attempts to block the most common type of exploit `attempts` to Joomla!
#
## Deny access to extension xml files (uncomment out to activate)
#<Files ~ "\.xml$">
#Order allow,deny
#Deny from all
#Satisfy all
#</Files>
## End of deny access to extension xml files
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
# Block out any script trying to base64_encode crap to send via URL
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
# Block out any script that includes a <script> tag in URL
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Send all blocked request to homepage with 403 Forbidden error!
RewriteRule ^(.*)$ index.php [F,L]
#
########## End - Rewrite rules to block out some common exploits

#  Uncomment following line if your webserver's URL
#  is not directly related to physical file paths.
#  Update Your Joomla! Directory (just / for root)

# RewriteBase /

########## 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

###### 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



Redirect works but cart doesn't

##
# @version $Id: htaccess.txt 13415 2009-11-03 15:53:25Z ian $
# @package Joomla
# @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
# @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
# Joomla! is Free Software
##

#####################################################
#  READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE
#
# The line just below this section: 'Options +FollowSymLinks' may cause problems
# with some server configurations.  It is required for use of mod_rewrite, but may already
# be set by your server administrator in a way that dissallows changing it in
# your .htaccess file.  If using it causes your server to error out, comment it out (add # to
# beginning of line), reload your site in your browser and test your sef url's.  If they work,
# it has been set by your server administrator and you do not need it set here.
#
#####################################################

##  Can be commented out if causes errors, see notes above.
Options +FollowSymLinks

#
#  mod_rewrite in use

RewriteEngine On
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]
########## Begin - Rewrite rules to block out some common exploits
## If you experience problems on your site block out the operations listed below
## This attempts to block the most common type of exploit `attempts` to Joomla!
#
## Deny access to extension xml files (uncomment out to activate)
#<Files ~ "\.xml$">
#Order allow,deny
#Deny from all
#Satisfy all
#</Files>
## End of deny access to extension xml files
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
# Block out any script trying to base64_encode crap to send via URL
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
# Block out any script that includes a <script> tag in URL
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Send all blocked request to homepage with 403 Forbidden error!
RewriteRule ^(.*)$ index.php [F,L]
#
########## End - Rewrite rules to block out some common exploits

#  Uncomment following line if your webserver's URL
#  is not directly related to physical file paths.
#  Update Your Joomla! Directory (just / for root)

# RewriteBase /

########## 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
Title: Re: AJAX not working on adding products to cart
Post by: Buildacomputer on July 08, 2010, 03:37:11 am
resolved the issue. I was putting RewriteBase /public_html/ when it wasnt needed as the htaccess file was already in root.

Thanks,
Title: Re: AJAX not working on adding products to cart
Post by: Gnani on September 02, 2010, 00:22:56 am
Hi friends. I've just run into the same problem but in reverse: ajax 'add to cart' DOESN'T WORK when there is www and works when it's removed.

I'm guessing it's best convention to have it defaulting to www using a .htaccess file as discussed above, but i need to find out why this problem is reversed to deal with it that way. Does anyone know why this may have happened and what i could do to fix it?
Title: Re: AJAX not working on adding products to cart
Post by: Forrest on October 07, 2010, 04:55:17 am
Probably because of what you have specified in your VM config!

Under URL and Secure URL settings... did you use http://www.mydomain.com?
Title: Re: AJAX not working on adding products to cart
Post by: QubeSys Technologies on November 04, 2010, 18:11:52 pm
This should fix my error also.
lets see.
Title: Re: AJAX not working on adding products to cart
Post by: msanad on April 25, 2011, 09:03:42 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



I have a weird problem, after moving my site to a different domain using this code i get this error in chrome: "has resulted in too many redirects. Clearing your cookies for this site or allowing third-party cookies may fix the problem. If not, it is possibly a server configuration issue and not a problem with your computer."

in firefox however I get this error: "The page isn't redirecting properly
          Firefox has detected that the server is redirecting the request for this address in a way that will never complete."


What could the issue be? I appreciate any help in the matter.
Title: Re: AJAX not working on adding products to cart
Post by: Forrest on April 26, 2011, 11:18:44 am
I am thinking you pasted BOTH codes into your .htacess file. You need to use ONE or other OTHER per the instructions :)

"Add this code at bottom of .htaccess, for both http, https:
... insert that code only.

Or

"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."
... then insert second set of code.

If you pasted the whole block of code like above, this likely is the cause.