|
Posted by Vladdy on 12/25/45 11:26
Roy Schestowitz wrote:
> __/ [Vladdy] on Monday 12 September 2005 07:51 \__
>
>
>>Roy Schestowitz wrote:
>>
>>>__/ [Neredbojias] on Monday 12 September 2005 05:44 \__
>>>
>>><SNIP>
>>>
>>>To rephrase my request as you were not sure what I meant, I seek to grab
>>>text from http://example.org/data.txt and then embed it in a <span>, for
>>>instance, in http://example.com/page.html. data.txt gets updated all the
>>>time, hence it needs to be grabbed. If JavaScript was disabled, there
>>>would be no harm either.
>>>
>>>Thanks again,
>>>
>>>Roy
>>
>>function getFile(filename)
>> { oxmlhttp = null;
>> try
>> { oxmlhttp = new XMLHttpRequest();
>> oxmlhttp.overrideMimeType("text/xml");
>> }
>> catch(e)
>> { try
>> { oxmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
>> }
>> catch(e)
>> { return null;
>> }
>> }
>> if(!oxmlhttp) return null;
>> try
>> { oxmlhttp.open("GET",filename,false);
>> oxmlhttp.send(null);
>> }
>> catch(e)
>> { return null;
>> }
>> return oxmlhttp.responseText;
>> }
>>
>>function returns file content as text string.
>>beware of x-domain scripting restrictions.
>
>
>
> Thank you very much for the reply.
>
> Below is the code that I have added as a wrapper. I still have a slight
> problem, which perhaps you can solve 'on the spot'. The following
> simplified example will work fine (I do not know JS methods):
>
> [CODE]
>
> function showInfo()
> {
> oxmlhttp =getFile('/robots.txt');
> document.write(oxmlhttp);
> }
>
> [/CODE]
>
> but the following will not
>
>
> [CODE]
>
> function showInfo()
> {
> oxmlhttp =getFile('http://example.org/robots.txt');
> document.write(oxmlhttp);
> }
>
> [/CODE]
>
> Is there a simple way around this? The text remains 'null' if I try the
> latter, which is why I need to access a machine of mine from the Web
> server.
>
> Thanks again,
>
> Roy
As I mentioned in my original post, the xmlhttp file access only works
within the same domain - security reasons. In the first example, the
same domain is assured by using the relative URL, in the second one, it
may not be (for example, you may need to add "www." to match the domain
of the page containing script; or it not work at all with the full
domain name - I have never tried it for the aformentioned reason)
--
Vladdy
http://www.klproductions.com
Navigation:
[Reply to this message]
|