user1469270
user1469270

Reputation:

jQuery .load(); not working

This is my first time trying this.

I have the following code in the head of an ajax.html:

$(document).ready(function(){
   $( "#result" ).load( "/loaded.html" );
});

Then in the same directory, I have a second page, loaded.html:

<div id="result">Hello!</div>

However #result is not loaded. I have double checked jQuery, and it's all plugged in.

Would anyone know what is going wrong?

Upvotes: 0

Views: 5887

Answers (1)

Barmar
Barmar

Reputation: 780713

It should be:

$("selector to load into").load("loaded.html #result");

You apply .load() to the DIV you want to load into. If you want to search in the loaded data for a specific DIV, put that selector after the URL.

And since you're loading from the same directory, don't put / at the beginning of the URL. That means to load from the webroot directory.

Upvotes: 2

Related Questions