SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    webdesign Percept's Avatar
    Join Date
    Jan 2003
    Location
    Belgium
    Posts
    397
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Google-suggest-like search for personal website

    Hi,

    I've been thinking about adding a Google-suggest-like searchbox (absence of better name to indicate what I need) to a website of mine which needs to work on my own database (so no google results). Does anybody know of some good tutorial(s) or free code to accomplish this ? I would write it myself but this is a little to advanced for me.

    It would have to be crossbrower -> as much as possible anyway ( IE - Firefox - Safari )

    Thanks in advance.
    Last edited by Percept; Mar 9, 2005 at 05:05.


  2. #2
    SitePoint Wizard gold trophysilver trophybronze trophy dc dalton's Avatar
    Join Date
    Nov 2004
    Location
    Right behind you, watching, always watching.
    Posts
    5,431
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you search around for XMLHttpRequest both here and on the web you will find SOME examples and maybe some code .... really cool stuff but also just now really getting the attention it deserves... Ill be learning it myself soon!

  3. #3
    SitePoint Evangelist ucahg's Avatar
    Join Date
    Apr 2001
    Location
    Sarnia, Ontario, Canada
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's not that hard actually to learn, if you are willing to put in the time.

    With this resource and a few hours, I created a secure httprequest login system. I only point this out because this was my first time using XMLHttpRequest and it didn't take me long. Granted I had some prior experience in javascript, but it was my first time using it in at least a year.
    Love it? Hate it? Helpful? Useless?
    Use the rate button to let me know what you think of my post!

  4. #4
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    With all due respect to ucahg, in my opinion the article fails miserably. If the goal was to explain XMLHttpRequest in baby steps, why does the script employ conditional compilation? Is the following going to make any sense to most people:
    /*@cc_on
    @if (@_jscript_version >= 5)
    try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
    try {
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
    xmlhttp = false;
    }
    }
    @else
    xmlhttp = false;
    @end @*/
    That looks like an ascii drawing in someone's signature. Even if that doesn't scare the reader away, if the reader tries to do some digging to find out the meaning behind the ascii art, the reader will find out that MS doesn't even document it's own conditional compilation feature.

    In addition, if you examine the rest of the function:
    Code:
    function getHTTPObject() {
      var xmlhttp;
      /*@cc_on
      @if (@_jscript_version >= 5)
        try {
          xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
          try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
          } catch (E) {
            xmlhttp = false;
          }
        }
      @else
      xmlhttp = false;
      @end @*/
      if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        try {
          xmlhttp = new XMLHttpRequest();
        } catch (e) {
          xmlhttp = false;
        }
      }
      return xmlhttp;
    }
    ...it should be apparent that if you can write a test like the following for non-IE browsers:

    if (!xmlhttp && typeof XMLHttpRequest != 'undefined')

    then you should be able to replace the ascii art with a similar test:

    if(typeof ActiveXObject != undefined)

    Using that conditional along with getting rid of the try-catch blocks would go a long way to making the code intelligible.

  5. #5
    SitePoint Evangelist ucahg's Avatar
    Join Date
    Apr 2001
    Location
    Sarnia, Ontario, Canada
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I agree, and I'll qualify that by saying when I learned it I did as I believe the author suggests and just took that chunk of code with the hand-waving that it works. If it's not the best way (and it seems it's not) than a better way would be more appropriate.
    Love it? Hate it? Helpful? Useless?
    Use the rate button to let me know what you think of my post!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •