View Full Version : AJAX Includes: Need 2nd var for location.href

05-24-2006, 04:59 PM
Greetings !

REF: http://www.dynamicdrive.com/dynamicindex17/ajaxincludes.htm

After months of looking for some way of using an external text file to populate a shopping cart table, I was fortunate to find DynamicDrive's AJAX Includes routine. I love it! It does everything I want and it was clean and easy to understand being a "copy+paste" JavaScripter.

The code works beautiful in identifying the first occurence of location.href.
It parses the filename (FN) and embeds FN.TXT from the same directory into a table where it belongs.

The problem I'm having is once the page has been sent to my shopping cart, the "Continue Shopping" button invokes a return to the original page from whence it started, AND appends its query string following a question mark. This query string screws up the return page appearance by populating the return page with multiple copies of the image and the shopping cart table. The number of times this happens is equivalent to the number of items actually in the shopping cart.

I believe to correct this, I need an additional "if/else" statement to deal with the "?" string as this string changes the rules for lastIndexOf("."), as there are many, many periods appended in the query string.

I don't know enough to correctly parse just the FN once the query string is added to it.

This is the code I have currently:

<SCRIPT LANGUAGE="JavaScript"><!--
var str=(location.href);
var number_1 = str.lastIndexOf('/') + 1
var number_2 = str.lastIndexOf('.')
var myVar = str.substring(number_1, number_2)
myVar = myVar + '.txt'

Test page:
"http://www.ony xxpressions.com/catalog/FS02.htm"

*Space intentionally entered for no spidering.

First time viewed, correctly embeds: FS02.txt

After adding items to cart, upon return, URL looks like this:

"http://www.ony xxpressions.com/catalog/FS02.htm?qty=2.00&sub=9.00&shp=0.00&dis=0.00&vch=0.00&tax=0.00&tot=9.00&sd=&tp.x=111&tp.y=11"

...and there are two copies of the image, and two copies of the table where the cart code belongs, but no cart as the URL cannot be validated.

I certainly would appreciate any help that can be offered.
Thank you,

PS: Sorry this is so long.....