Windows Scripting
  Home arrow Windows Scripting arrow Page 4 - Handling Live Web Content in WSH - Part 2
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

Handling Live Web Content in WSH - Part 2
By: Nilpo/Developer Shed Staff Writer
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2006-12-19

    Table of Contents:
  • Handling Live Web Content in WSH - Part 2
  • Making the Connection
  • Handling the Response
  • Handling Errors and Exceptions
  • Implementing a Workaround
  • Other Uses for XMLHttpRequest

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Handling Live Web Content in WSH - Part 2 - Handling Errors and Exceptions


    (Page 4 of 6 )

    That was simple enough, but now what?  There has to be more to it.  For instance, what if there is a server error while we are trying to connect?  How would we know, and better yet, how could we handle that in our script so that our script wouldn’t fail?

    In this section, I will be dealing with several more parts of the XMLHttpRequest object.

    Properties:

    object.ReadyState

    object.Status

    object.StatusText

     

    Methods:

    abort()

    getAllResponseHeaders()

    getRespondseHeader()

     

    Events:

    onReadyStateChange (not used)

    In order to catch errors and respond to them, we first need ways of monitoring what’s going on.  There are basically two ways of doing this: by monitoring the XMLHttpRequest object’s connection state and by monitoring the server's HTTP response codes.  The ReadyState and Status properties do that for us respectively.  The ReadyState property returns one of five possible integer values as listed below based on the connection state of the XMLHttpRequest object.

    Value

    State

    Description

    0

    Uninitialized

    Waiting for the Open method.

    1

    Loading

    Waiting for the Send method.

    2

    Loaded

    Send method called.  Status and headers available.

    3

    Interactive

    Some data received.  You may use ResponseBody and ResponseText to see currently available data.

    4

    Complete

    All data has been received.

    The Status and StatusText properties are used to monitor the server responses.  Status will return a numerical HTTP code and Status Text will return its text equivalent.  So examples might be “404” and “Not Found”, respectively.

    With these properties, we can easily monitor our conditions on both the client side and the server side.  Our first concern would be a connection error in the form of a timeout.  If we can’t make a connection in a reasonable amount of time we should stop the attempt before it throws an error in our script.

    More Windows Scripting Articles
    More By Nilpo/Developer Shed Staff Writer


       · After several good discussions and a good response from the first article, I decided...
     

    WINDOWS SCRIPTING ARTICLES

    - Introducing Two-Way Data Binding using Silve...
    - Silverlight 2.0 Application Development with...
    - Burning Multisession CDs with IMAPI2 in WSH
    - Creating a Silverlight 2.0 Application that ...
    - Burning CDs with the IMAPI2 Control
    - Burning CDs in Windows XP with WSH
    - Advanced Word Object Scripting
    - Reading and Printing Word Documents in WSH
    - Scripting Microsoft Word
    - Using WSH to Catalog MP3 Files
    - Reading MP3 ID3 Tags in WSH
    - A Brief Look at Menus in WPF
    - More Examples of Simplified Image Processing...
    - Completing a WPF To-Do List Application
    - Simplified Image Processing in GDI+





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT