Burts AIS, osCommerce & More Blog
New URL: www.osworld.biz

Friday, July 29, 2005

xmlhttprequest in advanced_search.php (aka AJAX)

I sat down to do this many months ago, but probably got bored of looking at code. Anyway, I just 40 minutes getting it working, and in my test installation it works OK! The problem is that I cannot package it up as a GPL contribution as the license for the Code that I re-used forbids it. So what I will do is put together a step-by-step tutorial showing how to do this (later on today [friday] hopefully if I can find time). It works fantastically well and would be a good addition to most stores I think! AJAX Implementation of Advanced Search (osCommerce) Here you can see what I mean - I've typed in "ma" into the advanced search input box. Using xmlhttprequest this requests all the products that have "ma" in the name (matrix, matrox, there's something about mary etc). In this example I'm about to click on the link to There's Something About Mary which will open up the relevant product_info.php page...

New URL: www.osworld.biz - thanks!


At 7/29/2005 09:43:00 AM, Blogger WizardsandWars said...

Sounds interesting.

What does it do?

At 7/29/2005 09:58:00 AM, Blogger Gary B. said...

I've updated the original post to show an image which speaks 1000 words. I thin this is a useful addition to osCommerce - the problem is how to distribute it as the license is not GPL so cannot be freely distributed with another GPL package. Any ideas?

At 7/29/2005 10:01:00 AM, Blogger Gary B. said...

To see an example (of the same sort of thing) have a look at the Google Suggest Tool at http://www.google.com/webhp?complete=1&hl=en which uses just about the exact same technology...

Good, eh?

At 7/29/2005 12:06:00 PM, Blogger WizardsandWars said...

Excellent! Very, very nice!

Hmmn, well, you know what they say, if you can't give it away......sell it.

At 7/29/2005 07:26:00 PM, Anonymous Anonymous said...

Does this handle sessions ok?

At 7/29/2005 10:25:00 PM, Blogger Gary B. said...

It sure does. I have the links via the xmlhttprequest going through the normal tep_href_link function...

At 7/30/2005 06:16:00 AM, Anonymous Anonymous said...


I dont know what the code you used limits, but perhaps you can post the code as a tutorial or provide the changes and a link to the source?

At 7/30/2005 08:05:00 AM, Blogger Gary B. said...

I think the only way to do it is to basically write up a step by step tutorial (with links to the code). Then anyone can do it themselves and there should be no problem with Distribution.

I now have an example uploaded and I think I have all the problems cured.


Feedback would be appreciated, before I write anything up, please.

At 7/30/2005 01:44:00 PM, Blogger Gary B. said...

Initial feedback from one of the Forums I posted it on:

1/ Suse 9.2, Konqueror. As soon as anything is typed in the search box Konqueror bombs out with a segfault

2/ Works OK, looks OK

3/ The default search function in OSC in fairly naff and only searches product titles. The advanced search default does exactly the same! I feel that for most users will only be confused /disappointed further by this addition.

I convert the search box in the column (or header) to search product description too, which, with smaller sites, is the most useful search improvement IMO.

4/ Works for me in Konq (3.3.2, Vector Linux 5).

So, it seems to work (in Konqueror) for some but not others. I am thinking of putting in a browser sniffer script to only show the new code if the browser is either IE or Firefox. There's no point using the code and risk losing/upsetting customers.

More feedback needed!

At 7/31/2005 03:48:00 AM, Anonymous Anonymous said...


Looks good - are you going to make the livesearch.php page avaiable?

BTW - I see my buddy is not the only one on the outs the HPDL....;)


At 7/31/2005 03:53:00 PM, Blogger Gary B. said...

Yup, I'll take some time out to document what I've done so far...sometime this week, time permitting!

At 8/03/2005 07:41:00 PM, Anonymous Jared Call said...

Thanks for releasing this!


At 8/03/2005 07:51:00 PM, Blogger Gary B. said...

Hey Jared

I haven't released it yet - wanted to get some feedback first...

I think someone else released something similar today (which does not work!)...

I already learned 3 years ago never to release anything without at least some testing!

I'm trying to find time to document the changes I made - hopefully tomorrow!


At 8/19/2005 01:20:00 AM, Blogger R.E. said...


I've worked quite a bit with AJAX and have implemented several solutions varying from "live search" results to AJAX/SOAP tier decoupling.

It would be a simple matter to code a live search for osC however may not be scalable. For example, you'll have to use "SELECT ... WHERE ... LIKE '%term%'". This will scan the entire table for matching rows. Now, if there are only a few hundred rows it may not be apparent the increased server load presented by the overhead of not only queries but also the request objects.

Let's consider this scenario: a store has 3,000 products and is using a live search function. The customer types 5 letters which sends / receives 5 requests. However, this also means 5 complete (and expensive) table scans.

I would recommend coding the JS to trigger the XMLHttp request code NOT on keyup but rather a timed delay. Code a .5 second delay before initiating the remote call to skip a few of the requests.

On a high volume site the savings will be incredible!



Post a Comment

<< Home

View Latest Posts

To View Newer Posts - Click Here!