How to read text file from different domain
I need some advice.
My situation is this:
I have a router with OpenWrt(Linux distribution) installed and a web server configured in it. This router act as a client in a local network.
I have created a simple web page on the Internet that enable the login to the openwrt web server.while I have to check whether the user, who request to login and the router are located in the same local network before I redirect the user. I have the IP of the router in the local network, which is always being updated remotely.
I tried to do something like this:
(The only way that worked so far for me..)
Is there any way that I can read some text file from the router instead ??
Image im = Image();
im.src = "http://" + ip + "/some_image.png";
return (im.width>0 || im.height>0 )
I tried loading a text file from the router into an iframe and then extracting the text value with JS from that iframe but for security reasons the browser does not allow it.
As far as I know the only way to read a text file would be using ajax,
but that is also disabled since the request is for another domain.
By the way, for some reason my solution does not always work.
Sometimes my function returns false, even when the image was loaded successfully in the remote page.(into a div for example)
side language can reach to computer inside a home network when the only data available is the local IP address.
Any help would be appreciated!
Maybe you can use ajax, by accessing a server side script, like php, that gets the file you want (with cUrl, or file_get_contents() ) and returns the content to ajax.
Thank you MarPlo for your advice but unfortunately that is not possible.
I have already tried to do that.
Sorry, I not know way is not possible. A PHP script can get the content of a page from other domain, and then to output it.
But if you tried, you know better. It was an ideea.
To be more accurate it is possible but in my particular case it isn't.
I will describe the issue to be more specific
I have a local network with router and 2 computers.
Computer #1 IP: 10.0.0.20
Computer #2 IP: 10.0.0.27
Notice that the above Ip addresses are local and valid only within the home network.
I couldn't figure out how to do it.
Due to browser security restrictions ajax request can not successfully retrieve data from a different domain or subdomain.
Thank you Julien,
your solution did work.
I solved it with Jquery:
are the only way to overcome the cross doamin obstacle.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)