XMLHttpRequest

T

Tom de Neef

1) The code below works fine with IE and FF when the requested file is
local.
2) But when I try to load the file from a http://www ... address IE does it
and FF fails.

So, from 1) I conclude that the code is correct. The XMLHttpRequest object
is created, the "GET" works, etc.
Since IE works in 2) I know that the file is accessible.
I have given up to understand why FF fails in 2).
Can you give it a look and advise me pls.
Tom

function LoadFile(how,url)
{
var req = false;
// branch for native XMLHttpRequest object
if (window.XMLHttpRequest && !(window.ActiveXObject))
{ try { req = new window.XMLHttpRequest() }
catch(e) { req = false }
}
else // branch for IE/Windows ActiveX version
{ if (window.ActiveXObject)
{ try { req = new ActiveXObject("Msxml2.XMLHTTP") }
catch(e)
{ try { req = new ActiveXObject("Microsoft.XMLHTTP") }
catch(e) { req = false }
}
}
}

if(req)
{ req.open(how, url, false)
req.send(null)
return req.responseText
}
return ""
}

LoadFile("GET",someFile)
 
J

Joost Diepenmaat

Tom de Neef said:
1) The code below works fine with IE and FF when the requested file is
local.
2) But when I try to load the file from a http://www ... address IE does it
and FF fails.

If you're testing this from a local file which is AFIAK the only way 1)
works, FF will prevent this from working because of access
restrictions. IIRC you should get a message which should give you the
choice to allow the local page to access the remote one and/or enable
UniversalBrowserRead. I can't seem to find the definitive document at
the moment, but it's touched at here:

http://developer.mozilla.org/en/docs/XML_Extras
 
T

Tom de Neef

Joost Diepenmaat said:
If you're testing this from a local file which is AFIAK the only way 1)
works, FF will prevent this from working because of access
restrictions. IIRC you should get a message which should give you the
choice to allow the local page to access the remote one and/or enable
UniversalBrowserRead. I can't seem to find the definitive document at
the moment, but it's touched at here:

http://developer.mozilla.org/en/docs/XML_Extras

That was quick! And adequate.
The problem was that I was testing the code from my PC. The httpRequest will
not repond if it must load from another domain. So, you can not test loading
a http://www. address unless the code runs on that site.
All solved.
Thank you.
Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,149
Members
46,695
Latest member
StanleyDri

Latest Threads

Top