Damien
Damien

Reputation: 4319

jQuery ajax.load doesn't load HTML into div element

This is kinda weird. I've got a workaround for this problem, but I was wondering if anyone knew why it wasn't working. I have a div element on the page called shippingSelect. When I do:

$('#shippingSelect').load('page.asp')

It does not load the corresponding HTML from page.asp into the shippingSelect element. Alternatively, if I do:

$('#shippingSelect').load('page.asp', function(data){
    $('#shippingSelect').html(data);
});

That does work. What's the deal there? Thanks all.

this is exactly what's being loaded...not a whole page:

<a href='#' onclick='getShipping(); return false'>Re-Calculate shipping</a> - <select name='ups_select' id='ups_select' onchange='calculateTotal(this.value);'><option value='13.04|03' selected>UPS Ground ($13.04)</option><option value='56.56|13' >UPS Next Day Air Saver - Gtd. 1 day ($56.56)</option><option value='96.52|14' >UPS Next Day Air. Early A.M. - Gtd. 1 day ($96.52)</option><option value='61.03|01' >UPS Next Day Air. - Gtd. 1 day ($61.03)</option></select>

Upvotes: 0

Views: 1871

Answers (3)

mkoryak
mkoryak

Reputation: 57918

The only thing that makes any sense here is that what .load does and what .html functions do are different based on the content passed into them.

You havent included the content so its hard to tell why it breaks, but i bet the page you are loading includes the <html> element and all kinds of other stuff you would never want to load into a div.

You probably dont actually want to load the entire page into our div just a section of it. It would be best to put an id on that section and load just that element like so:

$('#shippingSelect').load('page.asp #container')

see docs

Upvotes: 1

Shadow Wizard
Shadow Wizard

Reputation: 66399

Loading whole page into a div element is not adviced, it has lots of extra stuff you don't really need.

Try this for a start:

$('#shippingSelect').load('page.asp body');

To load only the body contents, if no luck add a placeholder around the actual contents, give it id and change 'body' to '#id_here'.

Upvotes: 0

Max Allan
Max Allan

Reputation: 640

Have you just missed to paste the semicolon or do you miss it in the original? $('#shippingSelect').load('page.asp');

Upvotes: 0

Related Questions