Skip to main content

Love the XMLHttpRequest Object

I was reading up on some XML and AJAX stuff the other day and came across the XMLHttpRequest Object - when I come across snippets of code like the example in the link, I always try to figure a way to incorporate it into my work.  I always ask myself is this something I can use and make my software more efficient?

This was something I most definitely could use as we have a system of part numbers in our database.  We have users that select part numbers to enter Selling Opportunities so I was able to use the code to look up the part numbers more quickly, showing the part numbers, qty on hand, and some other pertinent info.

Below is an example of some code:

Page1.asp

<html>
<head>
<script>
function showHint(str) {
    if (str.length == 0) {
        document.getElementById("txtHint").innerHTML = "";
        return;
    } else {
        var xmlhttp = new XMLHttpRequest();
        xmlhttp.onreadystatechange = function() {
            if (this.readyState == 4 && this.status == 200) {
                document.getElementById("txtHint").innerHTML = this.responseText;
            }
        };
        xmlhttp.open("GET", "test_source2.asp?q=" + str, true);
        xmlhttp.send();
    }
}
</script>
</head>
<body>

<p><b>Start typing a Part Number in the input field below:</b></p>
<form>
Part Num: <input type="text" onkeyup="showHint(this.value)">
</form>
<p><span id="txtHint"></span></p>
</body>
</html>

Here's the test_source2.asp code:

response.expires=-1
q=ucase(request.querystring("q"))

sql = "SELECT top 50 partnumfield, qty FROM partTable with (nolock) where partnumfield like '"  & q & "%' ORDER By partnumfield"
set rs = conn.execute(sql)

if len(q) > 0 then
  if not rs.bof and not rs.eof then
      do until rs.eof
          hint = hint & rs("partnumfield") & " (" & rs("qty") & ")<br>"
      rs.movenext
      loop
  end if
  rs.close
  set rs = nothing
end if

if hint="" then
  response.write("no matches")
else
  response.write(hint)
end if

Comments

Popular posts from this blog

Alexa Is Listening, Recording, and Sending!

Check out this story where a couple in Oregon was having a private conversation and Alexa recorded and sent the conversation to one of their contacts!  They were not aware until the contact contacted them about what had happened.  The couple contacted Amazon and they verified the series of events.  But what's even more bizarre is the couple wanted to return their Amazon home devices but Amazon has not agreed to return the costs for the devices! Check out the article here  by Bruce Brown on  Digital Trends

Cybersecurity

I went to a Cybersecurity conference last week hosted by  Data Connectors and I want to give kudos for the job well done in running the conference.  First of all they held the conference in a very nice Westin downtown, so the facility was great!  The Vendors were very informative and the presentations were very good as well!  There was a good mix of breaks so we could talk with the Vendors and learn more about their products.  The lunch and snacks were good too!  Always a plus! But back to the subject of Cybersecurity.  It's truly amazing all the cyber attacks made against companies, websites, home owners, smart phones, etc.  I don't remember the exact numbers, but at the time they presented them, I was amazed how high it is, and how high it's going to be.  Everything on the web is exposed and most people don't realize the bad exposure that's out there.  Yes, bigger companies are spending lots of money to protect their data but the ...

My Twitter Followers Have Gone Down!

If you're a Twitter user you might have heard or seen on your account the number of followers go down.  For some of us, those numbers might be minimal.  I have a Twitter account @NKYSports which I use in connection with one of my High School sports website NKYSports.com.  Last week I had about 6,070 followers.  That number today is down about 100.  But I have heard users who have followers over 50K, 100K, etc. losing thousands and thousands of "so-called" followers. So what happened?  Twitter has started cleaning accounts due to fake news scandals and data privacy.  That equates to about 1 million accounts the past quarter (2nd Q of 2018).  Twitter CEO Jack Dorsey says improving the health of the platform is critical for future growth. Twitter has been a great tool for my website, but I also like getting updates sent directly to my phone to get the latest news, sports, weather, etc.  I know what to believe and not to believe as well!...