-
Jun 30th, 2017, 03:36 PM
#1
Load Files at Runtime
I am rewriting my tutorial website and what I want to do is have one web page that will allow the user to load the lesson file into a column located on the page. This is a screenshot of my page layout:
As you can tell the user selects a file on the right-hand side which will then pull up a lesson on the left-hand side. The lesson is an HTML (without the <head> or <body> tags, just the raw HTML) and I tried using the following JQuery function to open the file and append the contents to the left-hand side column:
Code:
$(document).ready(function(){
// by default show the first lesson
jQuery.get('../../lessons/basics/indroduction.html', function(data) {
// append the file to the content area
$('#content').append(data);
});
$('.panel .panel-body ol li a').on('click', function() {
// get the root, directory, and file values
var root = 'lessons';
var directory = $(this).parent().parent().parent().parent().data('directory');
var file = $(this).parent().data('file');
var path = root + '../../' + directory + '/' + file + '.html';
// clear any existing lesson content
$('#content').empty();
// read the lesson file
jQuery.get(path, function(data) {
// append the file to the content area
$('#content').append(data);
});
});
});
However, whenever I try to use the code I get the following error:
XMLHttpRequest cannot load [file name]. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
So my question to y'all is how can I load my HTML file at runtime without having to do anything too crazy?
-
Jul 1st, 2017, 09:39 PM
#2
Re: Load Files at Runtime
as the error suggests, the request are only supported for certain protocols... if I'm reading the code right, you're not specifying one... so simply add a http:// to the front of your path before calling the get.
-tg
-
Jul 3rd, 2017, 09:27 AM
#3
Re: Load Files at Runtime
How can I test this during debug since I they're local files?
-
Jul 7th, 2017, 09:38 AM
#4
Re: Load Files at Runtime
You can call local html files using http you dont have to reference them as files.
If your using Visual Studio, then when you run your website or web application it runs under a local IIS service under localhost.
so you can call http:\\localhost:8080\webpagename.html
if your not using Visual Studio then its a little more difficult as your website is not running under a web server if you just open the pages directly in a browser, but you could always setup IIS locally on your machine and run your site under IIS, its not difficult to setup.
Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you
-
Jul 7th, 2017, 04:15 PM
#5
Re: Load Files at Runtime
I'm using Bootstrap Studios which essentially does the same thing (I think), so I think that'll work.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|