Handling Live Web Content in WSH - Part 2 - Handling the Response
(Page 3 of 6 )
The XMLHttpRequest object has built two built-in properties, ResponseText and ResponseXML, which capture the data returned by the server. The methods return the data as text or as an XML object respectively.
result = objxmlHTTP.ResponseText
Wscript.Echo result
We’ll finish up by echoing back the HTML text that was returned (which happens to be the source for our form submittal page). Our result should look something like this:
<html>
<head>
<title>XMLHttpRequest Test Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<font color="#FF0000">This form was submitted remotely.</font><p>Name : John Doe<br>
Address : 123 My Street<br>
</body>
</html>
So our complete code example would look like this:
strPostData = “action=data&name=John Doe” _
& “&address=123 My Street”
actionURL = “http://images.devshed.com/af/stories/hlwc2/testform.php”
Set objxmlHTTP = CreateObject(“Msxml2.XMLHTTP”)
objxmlHTTP.Open(“POST”, actionURL, True)
objxmlHTTP.setRequestHeader “Content-Type”, _
“application/x-www-form-urlencoded”
objxmlHTTP.Send(strPostData)
result = objxmlHTTP.ResponseText
Wscript.Echo result
Set objxmlHTTP = Nothing
Next: Handling Errors and Exceptions >>
More Windows Scripting Articles
More By Nilpo/Developer Shed Staff Writer