Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Object Expected with XMLHTTP

Status
Not open for further replies.

BrazilBill

Programmer
Dec 12, 2002
5
GB
Hi, can anyone help a newbie? First post.
I'm using XMLHTTP to test for the existence of an HTM file with VBScript, providing a link if it does (Cant rely on client environment to allow FileSystemObject without annoying ActiveX prompts). Usual thing, works fine on app. 90% of the XP and 2000 machines (other OS's not relevant), but on the remainder the 'Object Expected' runtime error displays, and causes the script to fall over.

All failing machines have identical browsers (IE6) to working ones. The HTM page in question pulls in a VBS from the header section, which contains something like (I'm at home, it's at work :0)

Code:
set xmlobj = CreateObject("Microsoft.XMLHTTP")
 
xmlobj.Open "GET", "myFile.htm", False
xmlobj.Send

If xmlobj.ResponseText <> "" then
  document.write("<A HREF = 'myFile.htm'>Link</A>")
end if

Could it be a security issue on certain machines? I really need to figure this one out so any help would be appreciated.

Cheers,

BB

 
Hello BrazilBill,

Trap the error this way may help.
Code:
on error resume next
set xmlobj = CreateObject("Microsoft.XMLHTTP")
if err.number=0 then
    xmlobj.Open "GET", "myFile.htm", False
    xmlobj.Send

    If err.number=0 then
        document.write("<A HREF = 'myFile.htm'>Link</A>")
    else
        err.clear
        document.write("<A HREF = 'myFile.htm'>Link -  resource unavailable at present</A>")   'or whatever
    end if
else
    err.clear
    document.write("<A HREF = 'myFile.htm'>Link - availability unverified<A>")   'or whatever
end if
on error goto 0
regards - tsuji
 
you need to wait for the request to return, try this:

Code:
set xmlobj = CreateObject("Microsoft.XMLHTTP")
 
xmlobj.Open "GET", "myFile.htm", False
xmlobj.Send


do while xmlobj.readyState<>4
loop


If xmlobj.ResponseText <> "" then
  document.write("<A HREF = 'myFile.htm'>Link</A>")
end if
 
Thanks Tsuji, the provision of the 'else' and error handling helped me track it down, and in the end it wasn't down to the vbs - it was a missing .js file in the directory containing the linked document (doh!) - your code is a lot tidier than mine, so it's going in! Thanks again, a great help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top