JQuery load () error but not JS error

I am trying to create a small simple JS framework for educational purposes, but now I have a problem that I cannot solve.

Directory structure

/
    /framework
        jquery.js
        init.js
    /content
        home.html
        style.css
    index.html

Problem

I obviously don't insert the jQuery file and stylesheet here, but here is index.html and init.js:

index.html

<!DOCTYPE html>
<head>
    <script src="framework/jquery-1.5.min.js"></script>
    <script src="framework/init.js"></script>
    <title>My website</title>
</head>
<body>
    <div id="content">

    </div>
</body>
</html>

init.js

$(document).ready(function(){
    if(!window.location.hash) {
        $("#content").load("../content/home.html", function() {
            alert("Load was performed.");
        });
    }
});

The home.html file contains some sample text, nothing special. I expect jQuery to load the contents of home.html into the contents of the div, but nothing happens when I load the page. However, a warning message saying "Download has been completed."

This task seems rather trivial for me, so the mistake I made is probably pretty stupid, but any help, however, is greatly appreciated.

Thank!

Update:

, , localhost . Firebug, , . ?

+3
4

jquery 1.5. - http://bugs.jquery.com/ticket/8125. 1.5.1, google microsoft cdn. jquery , load() http://code.jquery.com/jquery-git.js

, 1.5.1

+7

Firebug, NET. ajax.

, : /content/home.html, ../content/home.html

, JS.

+6

The base place for the script to execute is the location of index.html, so the relative path to home.html is "content/home.html", not "../content/home.html".

+2
source

just try with ./

$(document).ready(function(){
    if(!window.location.hash) {
        $("#content").load("./content/home.html", function() {
            alert("Load was performed.");
        });
    }
});

which works for me at least.

0
source

Source: https://habr.com/ru/post/1790311/


All Articles