Link to home
Create AccountLog in
Avatar of giligatech
giligatech

asked on

Registering (httpXML) onreadystatechange to a Function in ASP

Hi my code goes lilke this:

<%
Dim oXML
Set oXML = Server.CreateObject("MSXML2.ServerXMLHTTP")
oXML.onreadystatechange = StatusChanged()
oXML.Open "GET", "http://www.yahoo.com", False
oXML.Send

Function StatusChanged()
    if oXML.readyState = 3 OR oXML.readyState = 4 Then
        response.Write oXML.status
        response.End
    end if
End Function

%>

(As you can see, I'm trying to register the function StatusChanged() to be called whenever the status changed)

But I get this Error:

Type mismatch: 'oXML.onreadystatechange'
SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of giligatech
giligatech

ASKER

My real problem is that i need to know if the Status changes
(if the status is 200 do one thing and if it's 301/302 do another thing).

Which of the solutions here will work for that?
Dim oXML
Set oXML = Server.CreateObject("MSXML2.ServerXMLHTTP")
oXML.Open "GET", "http://www.yahoo.com", False
oXML.Send

'when the request is complete, you just checke the status and do whatever
If oXML.status = 200 Then
'whatever
ElseIf oXML.status=301 Then
'whatever
Else
'whatever
End If
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
>>... the key is the WithEvents
All you need is to send the request in SYNCHRONOUS mode and once the request completes check the state. This is what I showed in my previous post. Can't get simpler than that. THAT is literally the code needed (except he will have to provide the real url).
OK, listen up.
SYNCHRONOUS  or  ASYNCHRONOUS ,

lets say I have a file called a.asp:
<%
response.redirect "b.asp"
%>

If I will do:

Dim oXML
Set oXML = Server.CreateObject("MSXML2.ServerXMLHTTP")
oXML.Open "GET", "http://www.myserver.com/a.asp", False (or True)
oXML.Send

oXML will have the state 200 (OK) and It will redirect me AUTOMATICALLY to b.asp
(I will not even know that).
It won't show me state 302 / 301.

What sould I do?
ASKER CERTIFIED SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account