Reputation:
I'm trying to display and extract a string from another page. The page in question will be a ftp:// HTML page. I've tried a few different methods and have been reading several similar posts that don't answer my question.
The page I'm requesting will only have one line, which is the line I need.
For example when Home.html
is the main page. Then when returned.html
is the page I am requesting, and it simply contains true
or false
.
My code
<script type="text/javascript">
var HTML = function ( address, callback )
{
if ( !window.XMLHttpRequest ) return;
var xhr = new XMLHttpRequest();
xhr.onload = function() {
if ( callback && typeof( callback ) === 'function' ) {
callback( this.responseXML );
}
}
xhr.open( 'GET', address );
xhr.responseType = 'document';
xhr.send();
};
function GetResponse()
{
getHTML ('ftp://192.168.2.5/1.html', function (response) {
var docele = document.querySelector('divNext');
docele.innerHTML = response.documentElement.innerHTML;
});
}
</script>
<style>
div.hidden {
display:none;
}
div.visible {
display:visible;
}
</style>
In this I'm trying to load the page into a div, but I'm also needing that into a variable to define other things later on.
Upvotes: 0
Views: 54
Reputation: 943142
Since switching to ftp
involves a change of protcol, you will hit the Same Origin Policy.
Since you aren't requesting the document over HTTP, you can't add the HTTP headers needed to grant you permission to access the document via CORS.
So there is no way to directly access the FTP server from JavaScript in the page.
You need to make the data available over HTTP. You could do this by writing server side code to proxy it on the server hosting the HTML document you are embedding the JavaScript in.
If you want to write the code in JavaScript, you can use Node.js to run it on your server.
Upvotes: 1