Results 1 to 5 of 5

Thread: Load Files at Runtime

  1. #1

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    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:
    Name:  lessons screenshot.jpg
Views: 466
Size:  16.5 KB
    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?
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: Load Files at Runtime

    How can I test this during debug since I they're local files?
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  4. #4
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,660

    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



  5. #5

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: Load Files at Runtime

    I'm using Bootstrap Studios which essentially does the same thing (I think), so I think that'll work.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width