How to load local html file?

How to load local html file?

Postby rjot » Wed Jun 25, 2014 4:52 am

Hello,
In LG .load() from jQuery works, but in SDK Alliance emulator don't work. I'll try:
Code: Select all
1. $( \"#dynamicContent\" ).load( \"./html/currency.html\");

2. $( \"#dynamicContent\" ).html( loadPage(\"html/currency.html\"));
function loadPage(href) {
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open(\"GET\", href, false);
    xmlhttp.send();
    return xmlhttp.responseText;
}

3. var url = './html/currency.html';
$.get(url, function(response) {
    $('#dynamicContent').html(response);
})

so, how to load local html file?
rjot
 
Posts: 11
Joined: Thu Mar 27, 2014 6:46 am

How to load local html file?

Postby Support_STA » Wed Jun 25, 2014 6:29 pm

Hi,

In your case, we suggest you should use absolute path instead of relative path to make sure about it.
Maybe, emulator get problem with relative path as you did.
Aside, you can check root problem by Console Tab (open by \"Inspect Element\" option in menu context -> Choose Console Tab).
Hope this help!

Regards,
STA Support
Support_STA
 
Posts: 136
Joined: Fri Aug 09, 2013 3:56 am

How to load local html file?

Postby rjot » Thu Jun 26, 2014 1:33 am

hi, thanks for ur reply. I'll try with absolute path, but still shows the same errors: \"URL cannot be shown\", i prepare test app with this issue.
Code: Select all
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
        <title>Test Load</title>
        <script type=\"text/javascript\" src=\"http://code.jquery.com/jquery-2.1.1.min.js\"></script>
        <script type=\"text/javascript\">    [size=2][/size]
            $(document).ready(function() {
                var absoluteLoc = window.location.protocol + '//' + window.location.pathname;
                var absolutePath = absoluteLoc.substr(0, absoluteLoc.lastIndexOf(\"/\"));
                console.log(absolutePath);
               
                $('h1').click(function() {                   
                    $( \"#dynamicContent\" ).load(\"content.html\");
                   
                    $( \"#dynamicContent\" ).load( absolutePath + \"/content.html\");
                   
                    $.get(absolutePath + \"/content.html\", function(response) {
                        $('#dynamicContent').html(response);
                    });
                   
                    $( \"#dynamicContent\" ).html( loadPage(absolutePath + \"/content.html\"));
                });
            });
            function loadPage(href) {
                var xmlhttp = new XMLHttpRequest();
                xmlhttp.open(\"GET\", href, false);
                xmlhttp.send();
                return xmlhttp.responseText;
            }
        </script>
    </head>
        <h1>Load content.html</h1>
        <div id=\"dynamicContent\"></div>
    </body>
</html>

in content.html
Code: Select all
<h2>Yupii, u make it!!!</h2>
rjot
 
Posts: 11
Joined: Thu Mar 27, 2014 6:46 am

How to load local html file?

Postby supporter lead_1 » Fri Jun 27, 2014 2:25 am

Hi,

I think you open your file in offline status (just open html file and load an local html file by ajax). Not only you, but also much others can't do it.
To do same thing in offline status, you can use iframe instead of ajax load.

Regards,
STA Support
supporter lead_1
 
Posts: 2
Joined: Mon Jul 27, 2015 12:37 am


Return to General questions



cron