0

I have a bunch of links that I want to load dynamically within the page. Instead of writing out a massive statement for every link I want to grab the URL from the attribute and pass it where I need it.

The code below works if I put an address instead of the variable name linkURL so I know the code works. Firebug shows it looks for the right URL at first but when it gets to the

.load('linkURL .columnWide');

section it starts looking for linkURL

// AJAXin links

// Click on link within id with ending of ASPX triggers this
$('#element a[href$=aspx]').click(function(e) {

    // Grab the href attribute and use it as linkURL variable
    var linkURL = $(this).attr('href');
    // AJAX
    $.ajax({

    // Use the variable linkURL as source for AJAX request
    url: linkURL,
    dataType: 'html',

    success: function(data) {
        // This is where the fetched content will go
        $('.result1')
            // HTML added to DIV while content loads
            .html('<div id="spinningLoader"><img class="loader" src="spinnerBlack.png" alt="spinnerBlack" width="100" height="100" /></div> ')
            // Load from this URL this class
            .load('linkURL .columnWide');

        // See above
        $('.result2')
            .html('<div id="spinningLoader"><img class="loader" src="spinnerBlack.png" alt="spinnerBlack" width="100" height="100" /></div> ')
            .load('linkURL .columnNarrow');

        // It worked mother flipper
        $.print('Load was performed.');
    }
    });
});

EDIT: I probably shouldn't publish links to things in my s3 buckets :s

3
  • What doesn't work? What is the question / problem? Commented Aug 11, 2010 at 11:26
  • Have you tried to debug this code using Firebug or Opera Dragonfly? You should check if linkURL keeps the address. Commented Aug 11, 2010 at 11:28
  • I don't see what's problem here? Commented Aug 11, 2010 at 11:28

1 Answer 1

2

You need to modify you load lines thus .load(linkURL + ' .columnWide')

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

1 Comment

A pleasure to help, just remember, Javascript (and in fact many programming languages) will not parse variable names inside string literals.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.