Windows Scripting
  Home arrow Windows Scripting arrow 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 
Dedicated Servers 
Actuate Whitepapers 
Moblin 
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

    Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Handling Live Web Content in WSH - Part 2


    (Page 1 of 6 )

    In part one of this article we began to explore the XMLHttpRequest object and how it could be used to interact with live web content. We focused primarily on reading the contents of a web page (a technique known as “screenscraping”) and parsing that data into our script. This time we are going to take a look at the rest of the methods provided by the XMLHttpObject and how we can use them to send data to a web server for remote form submission.

    You may want to review part one of this article before going any further if you need to refresh your memory. The XMLHttpRequest object is a versatile tool because it’s installed by Internet Explorer (which means that it’s native to every machine on which you run your script). Its simple construct also makes coding this into your scripts as painless as possible.

    We’re going to use the XMLHttpRequest object to submit POST data to a form. In order to do this we’ll need two things. The first is the full URL where we want to send our request. You can find this by looking at the source code for the form.  The URL will be in the action attribute of the <form> html tag. Remember that this may be a relative reference so you may have to include the rest of the URL from your browser’s address bar. I have uploaded a sample form to use when testing this script. It is located at the following URL:

    http://images.devshed.com/af/stories/hlwc2/testform.php

    Next, we need to construct our POST data string.  This is just a string that contains simple data field-value pairs for the form fields that we want to submit.  Each data field is separated from the next by an ampersand (&) just as if we were appending it to a URL. The only difference is that we do not need to encode it, so any special characters are okay.

    Our example uses two form fields: “name” and “address.” It also contains a hidden field named “action” whose value is set to “data” by default. Let’s assume we want to submit the following data in our form:

    Name:    John Doe

    Address: 123 My Street

    With this information, we would construct the following POST data string which I’ve separated across two lines for aesthetic purposes:

    strPostData = “action=data&name=John Doe” _

       & “&address=123 My Street”

    actionURL = “http://images.devshed.com/af/stories/hlwc2/testform.php”

    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

    - Understanding Procedures in VBScript
    - Printing Documents in WSH
    - Generating Outlook Signatures Based on Activ...
    - VBScript: Converting and Formatting with Fun...
    - VBScript: Conversion and Format Functions
    - VBScript: Array Functions
    - VBScript: Strings, You Can`t Function withou...
    - VBScript: More String Functions
    - VBScript: Functioning with Strings
    - Working with the Windows Registry in C++
    - Understanding Objects
    - HTML Applications: Giving WSH a User Interfa...
    - Modifying Computer Objects with Active Direc...
    - Logon Script to Send Email Notifications
    - Securing Computers and Active Directory





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway