Page 1 of 1

jquery animation problem

Posted: Thu Jun 28, 2007 2:32 pm
by smudge
Hi all. I'm using jquery to load a page based on which link in the navbar the user clicks on:

Code: Select all

$(function(){
  $('.navBar a').click(function(){
    $('#body').hide('normal');
    $('#body').load(this.href,{ajax:true});
    $('#body').show('normal');
    return false;
  });
});
This works, except that if you click on the link, the script hides #body, then updates it, then nothing. If you click the link again, it shows the new information. Obviously, I don't want the user to have to click the link twice. I tried adding alerts to help debug, and I found that if you add an alert("whatever") between the load and show commands, the script works, but I don't want to have it alert the user when he/she clicks it either. Any ideas on how to fix this would be much appreciated.

Posted: Thu Jun 28, 2007 2:40 pm
by Luke
Try using callbacks...

Code: Select all

$(function(){
  $('.navBar a').click(function(){
    $('#body').hide('normal', function(){
      $('#body').load(this.href,{ajax:true}, function(){
        $('#body').show('normal');
      });
    });
    return false;
  });
});
It's all in the docs.

Posted: Thu Jun 28, 2007 2:51 pm
by smudge
I tried that, but when I ran it, #body hid itself and firebug reported this error:

uncaught exception: [Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIXMLHttpRequest.open]" nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)" location: "JS frame :: javascript: eval(__firebugTemp__); :: anonymous :: line 1" data: no]
Line 0

I have no clue what that means.