Home arrow ASP arrow Page 3 - Real Time Data Grid Part 2/2

Real Time Data Grid Part 2/2

In this article Annette wraps up the details of the real time data grid that she started to describe in part one of this two-part article. She looks at the JavaScript code that contacts our database server and allows us to update data in a database without actually refreshing the page.

Author Info:
By: Annette Tennison
Rating: 5 stars5 stars5 stars5 stars5 stars / 21
February 08, 2002
  1. · Real Time Data Grid Part 2/2
  2. · The JavaScript code
  3. · The JavaScript code (contd.)
  4. · The doDel JavaScript function
  5. · Using our DynamicGrid class
  6. · Conclusion

print this article

Real Time Data Grid Part 2/2 - The JavaScript code (contd.)
(Page 3 of 6 )

Our SendRemoteRequest JavaScript function creates a new instance of the MSXML2.XMLHTTP class, which allows us to retrieve the contents of any page on a HTTP web server (assuming that we have the permissions to do so). The strPage variable contains the URL to the page we want to retrieve. You'll notice that the strPage variable contains the URL of our dynamic.datagrid.asp page, as well as the variable of the query argument tacked onto the end.

Next, we call the open method of our XMLHTTP object, and actually retrieve the requested page using its send method. We wont go into too much detail about the XMLHTTP library in this article, but if you'd like to read up on it, then checkout Mitchell's article on it here. The page being retrieved is our ASP script, but with a query string variable named "query" passed to it.

At the top of our ASP script, before the declaration of our DynamicGrid class, we have the following lines:

strQuery = Request.QueryString("query")

If strQuery <> "" Then



End If

When we request this page using the XMLHTTP object through JavaScript, it sees that we have passed in a query string variable named query and calls the RunQuery method. The RunQuery method executes this query against our database and returns either true/false, indicating whether or not the query succeeded:

objConn.Open strConnectionstring

objComm.ActiveConnection = objConn

objComm.CommandText = Query


If err.number = 0 And objConn.Errors.Count = 0 Then

Response.Write "true"


Response.Write "false"

End If

As soon as the RunQuery sub is finished, the Response.End method tells our XMLHTTP object that it has finished. We capture the output from this page using the responseText member of our XMLHTTP object and return it from our JavaScript function:

return objXMLHTTP.responseText;

Because our RunQuery ASP routine suppressed all error messages, the responseText method will only return the string "true" or "false". Jumping back to our doUpdate JavaScript function, we check the value returned from the call to the SendRemoteRequest function:

blnSuccess = SendRemoteRequest(strQuery);

if(blnSuccess == "true")


window.status = "Field '"+strFieldName+"' updated for record #"+(recordId+1)+" successfully.";

setTimeout("window.status=''", 2000);




alert("An error occured while trying to update record.");


If it's "true", then the SendRemoteRequest function succeeded and updated our database successfully. We set the status text of the browser window to let the user know that record was updated, and use the setTimeout function to set the status text back to nothing after two seconds:

Changing the window status text

If the SendRemoteRequest function failed, then we display a message box telling the user that the record couldn't be updated:

Shown when the update failed
blog comments powered by Disqus

- Central Scoreboard with Flash and ASP
- Calorie Counter Using WAP and ASP
- Creating PGP-Encrypted E-Mails Using ASP
- Be My Guest in ASP
- Session Replacement in ASP
- Securing ASP Data Access Credentials Using t...
- The Not So Ordinary Address Book
- Adding and Displaying Data Easily via ASP an...
- Sending Email From a Form in ASP
- Adding Member Services in ASP
- Removing Unconfirmed Members
- Trapping HTTP 500.100 - Internal Server Error
- So Many Rows, So Little Time! - Case Study
- XDO: An XML Engine Class for Classic ASP
- Credit Card Fraud Prevention Using ASP and C...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials