xmlhttprequest in advanced_search.php (aka AJAX)

Written by: burt
Date: July 29, 2005
Filed under: osCommerce
Trackback

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…

Comments

  1. Comment by WizardsandWars — July 29, 2005 @ 9:43 am

    Sounds interesting.

    What does it do?

  2. Comment by Gary B. — July 29, 2005 @ 9:58 am

    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?

  3. Comment by Gary B. — July 29, 2005 @ 10:01 am

    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?

  4. Comment by WizardsandWars — July 29, 2005 @ 12:06 pm

    Excellent! Very, very nice!

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

  5. Comment by Anonymous — July 29, 2005 @ 7:26 pm

    Does this handle sessions ok?

  6. Comment by Gary B. — July 29, 2005 @ 10:25 pm

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

  7. Comment by Anonymous — July 30, 2005 @ 6:16 am

    Gary,

    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?

  8. Comment by Gary B. — July 30, 2005 @ 8:05 am

    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.

    http://www.1month.co.uk/osc/advanced_search.php

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

  9. Comment by Gary B. — July 30, 2005 @ 1:44 pm

    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!

  10. Comment by Anonymous — July 31, 2005 @ 3:48 am

    Gary,

    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….;)

    Chris

  11. Comment by Gary B. — July 31, 2005 @ 3:53 pm

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

  12. Comment by Jared Call — August 3, 2005 @ 7:41 pm

    Thanks for releasing this!

    -jared

  13. Comment by Gary B. — August 3, 2005 @ 7:51 pm

    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!

    G.

  14. Comment by R.E. — August 19, 2005 @ 1:20 am

    Gary,

    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!

    Bobby

Sorry, the comment form is closed at this time.


Did you enjoy reading this?
Please consider subscribing to our RSS Feed!


Subscribe by Email
Get notified by email every time we update this Blog!


 

Subscribe (RSS)

Recent Comments

Sponsored By

What Others Are Saying