0

For the site I'm building, I'm trying to dynamically load content from other html files into the index.html (so when you click a nav link it won't load a whole new page, it will just load in content from a different html file). I've been told the best way to do this is using jquery.

I've included the jquery library up in my page head, and I'm able to call the .js file where the code will live (it successfully loaded an alert('boo')), but none of the content within the jquery functions will load. Here's the code:

<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"</script>
<script src='js/script.js'></script>

and then in the scrpt.js file:

$(document).ready(function()    {
    $('#content').load('content/index.html');
});
3
  • You know you don't close your first script tag, right? Does it make any difference if you do? Can you provide any debugging information at all, or are we to guess? What's in your network tab? See an HTTP request? Anything in the console? Commented Jun 24, 2013 at 3:39
  • 1
    Are you loading jQuery as well as jQuery UI? Commented Jun 24, 2013 at 3:40
  • submit the edited code you have not close the script tag for first one Commented Jun 24, 2013 at 4:21

2 Answers 2

1

Do like this:

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script src="js/script.js"></script>

...
<div id="content"> </div>
...

<script>
    $(document).ready(function()    {
        $('#content').load('content/index.html');
    });
</script>

be sure to not forget or mistake the #content and be sure 'content/index.html' can be reach from the actual page. No reason it is not working

EDIT: Be sure to not forget load jquery since jquery != jquery ui

Sign up to request clarification or add additional context in comments.

Comments

0

Have you tried adding HTTP to your call to jquery:

<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"</script>

Also you are missing a closing > on your script tag:

<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>

6 Comments

This is not the solution. URLs with // are valid, and will use whatever the current protocol is.
@Brad: It may very well be the solution if OP isn't using a webserver and is opening the HTML files directly with his browser.
I have had issues in the past when I omitted the http as it was trying to go to: mydomain.com//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js, which I think might depend on settings off the webserver, however I am not sure
@JanR, I don't believe you. You probably had something inserting your hostname and base path in before your links. I guarantee you that if you use // at the beginning of a URL in HTML, it will work fine.
Could be, in my case adding the http was the solution :)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.