Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery's load function doesn't work locally

I have to load an HTML file in a existing div when the window's width is smaller than 600px.

The code is:

<head>
<script>
    $(document).ready(function(){
        if($(window).width() < 600) {
           $("#testing_div").load("C:/Users/elena/Desktop/Demo/prova.html");
        }
    });
</script>
</head>
<body>
    <div id="testing_div"> </div>
</body>

I have tested this code on my website and it works, but maybe I am doing something wrong to make it work locally.

Is there a reason why the load function doesn't work locally but only on a web server?

like image 725
Maki Avatar asked Nov 12 '15 09:11

Maki


1 Answers

The reason is security. Running web pages through file:// protocol have disabled a lot of features because security issues. You can make a webserver in javascript through Node.js and you can have a webserver in the local without installing apache or something similar.

Node.js webpage:

https://nodejs.org/en/

like image 182
Marcos Pérez Gude Avatar answered Oct 05 '22 21:10

Marcos Pérez Gude