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

Nonclustered Index in SQL Server

So, I've run into an issue with one of my queries because it takes about 40 seconds to run and according to the Recent Expensive Queries section of the Activity Monitor in SQL Server, there is a section of code taking up about 51% of the query.  First, let me say that I've been writing Transact SQL for quite awhile but have never ventured into the Clustered and NonClustered areas of forming Indexes.  I do use indexes on all my tables but that's just the regular Primary Unique key.  We've been using this query for awhile and it does work but when the result set is about 5K records it takes a little while to run.  So here's the actual query itself SELECT PartNo , SerialNo , HeciCode , ScanDate , OrderType , PoNo , po . IssueDate , SoNo FROM ScanHistory sh WITH ( NOLOCK ) LEFT OUTER JOIN trkRWPOHeader po WITH ( NOLOCK ) ON sh . PoNo = po . PONum WHERE len ( PoNo ) > 2 AND ScanDate >

File Size Upload Limits using Godaddy Hosting

I've been working on a new project for a friend of mine and came across an issue with trying to upload photos using the infamous freeASPUpload code.  I've used the code in the past for some past projects but don't recall having issues with limits on uploading files. I'm posting this on my blog b/c there's nothing on the internet that discusses this (or at least I wasn't able to find any explanations), and hopefully this can be a resource to someone else that comes across the same issue. Now I know there are other options, utilities, etc. for uploading pics/files/etc. but  freeASPUpload  is simple, I've used it in the past, and this project is pretty basic.  So, if you want to change the upload file size limit you will first want to go into your Godaddy's hosting account.  Next go into the Virtual Directories option, then click on Directory Properties.  Towards the bottom there is a section called "Maximum size of entity body of an ASP request