jquery animation problem

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
smudge
Forum Contributor
Posts: 151
Joined: Sun May 20, 2007 12:13 pm

jquery animation problem

Post 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.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post 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.
smudge
Forum Contributor
Posts: 151
Joined: Sun May 20, 2007 12:13 pm

Post 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.
Post Reply