Using microsoft.xmlhttp asynchronously

boomerkang

New Member
How does one set the onreadystatechange property if using an xmlhttp request asynchronously? My code:

Code:
DEFINE VARIABLE httpReq AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE l-url AS CHARACTER INIT 'http://www.google.com' NO-UNDO.

FUNCTION requestHandler RETURNS LOGICAL:
       MESSAGE "httpReq:readyState =" httpReq:readyState VIEW-AS ALERT-BOX.
       RETURN ?.
END FUNCTION.

CREATE 'microsoft.xmlhttp' httpReq.

httpReq:open('GET', l-url, TRUE).

httpReq:onreadystatechange = 'requestHandler'.

httpReq:setRequestHeader('Content-Type', 'text/xml').

httpReq:send().

Doing this results in a runtime error:

"Error occurred while accessing component property/method: onreadystatechange. Type mismatch."

I've tried everything I can think of. Any help would be appreciated...
 

agnaldo.macedo

New Member
Try

Code:
DEFINE VARIABLE httpReq AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE l-url AS CHARACTER INIT 'http://www.starweb-software.com.br' NO-UNDO.
DEFINE BUTTON btn LABEL "Test".
DEFINE FRAME fr1
    btn
WITH CENTERED.
 
ON "choose" OF btn 
   DO:
      RUN httpReq.onreadystatechange.
  END.
 
CREATE 'MSXML2.ServerXMLHTTP' httpReq. 
httpReq:open('GET', l-url, TRUE).
httpReq:setRequestHeader('Content-Type', 'text/xml').
httpReq:send().
ENABLE ALL WITH FRAME fr1.
WAIT-FOR WINDOW-CLOSE OF CURRENT-WINDOW.
 
PROCEDURE httpReq.onreadystatechange : 
   IF httpReq:readyState = 4
      THEN
          DO:
             IF httpReq:status = 200
                THEN 
                     MESSAGE httpReq:responsetext VIEW-AS ALERT-BOX.
          END.            
END PROCEDURE.
 

boomerkang

New Member
Thanks for the reply. While not exactly what I was looking for, it is helpful.

Given further reading, it turns out the onreadystatechange property was not implemented in the COM object - it was intended for use with scripting clients (i.e. JavaScript in a browser).

I guess I should be more specific with what I'm looking to do: I'd like to make the HTTP request and then "do something" - let's say, fill in some fields - when it's done. However, I don't want to use a synchronous HTTP request, as that will tie up the Progress session waiting for it to complete - asynchronous is the only option.

I guess the most straightforward way to go is to use a PSTimer - make the HTTP request, let the user do some stuff, and let the OCX.Tick event keep checking the HTTP request, eventually filling the fields. While not elegant, it'll work.

This brings up a new question - is there a way in Progress to create a trigger on something other than a widget or a table? Given the code above, something like this:

Code:
ON VALUE-CHANGED OF httpReq:readyState DO:
    IF (httpReq:readyState = 4) THEN                         /* It's done */
        <some stuff>.
END.

By the way, I'm on 9.1E. I'm guessing the Web Service stuff added to OE10+ might be helpful for what I'm trying to do (without knowing much about it), but an upgrade is not possible.

Thanks.
 
Top