1
$("a[rel=profile]").live('click',function() {
            var profileURL = $(this).attr('href')         
            $.ajax({
                url: profileURL,
                success: function(data) {
                    alert(data)
                    $("#profile").html(data);
                    $("#profile").fadeIn();
                  }
            });                                   
            return false;
        })

Can anyone tell me what is wrong with this code, when I click the link with rel=profile it fires the alert() with the remote URL content but doesn't load it into the div and then fadeIn()

Thanks in advance :)

4
  • That all depends on what data is expected to be. What are you getting back? Commented May 12, 2011 at 14:02
  • Its the content of the remove URL... Commented May 12, 2011 at 14:03
  • 2
    I'd probably use the load extension for this like pixelbobby has suggested but maybe you're just missing dataType: "html" from your ajax declaration. Commented May 12, 2011 at 14:10
  • Quick note (little off topic), the above code will throw an error in IE. This is because there needs to be a semicolon at the end. The reason it will still work in other browsers is because they have semicolon insertion and I believe that IE does not (including IE9). Commented May 12, 2011 at 14:10

1 Answer 1

2

Why don't you just try something like this instead. See the API for the Load function. You can also pass it a callback so you can do something after the load is complete like so:

$("a[rel=profile]").live('click', function() {
    $('#profile').load( 
        $(this).attr('href'), 
        function(){ $('#profile').fadeIn();});

    return false;
});
Sign up to request clarification or add additional context in comments.

5 Comments

I was using load() originally but it was running very clunkily, it seemed to work fine using $.ajax...
It actually seems to have fixed itself after a good refresh :) but this is the best answer of the bunch.
@Chris You might be interested in seeing this Load. Basically the load function is just a wrapper around a set of defaults on the $.ajax function.
Glad I could be of assistance @Chris. Happy venturing w/ jQuery. It's a pretty gnarly ride :)
Thanks @Nicky thats really interesting, seeing the behind code gives this some well needed perspective! and @Pixelbobby cheers for your help mate, have streamlined the code and have actually ended up using your load with callback now :)

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.