JQERY newbie ?

  • s15199d
  • Expert
  • Expert
  • User avatar
  • Joined: Feb 20, 2004
  • Posts: 524
  • Loc: NC, USA
  • Status: Offline

Post September 2nd, 2009, 12:07 pm

The code below works fine in FireFox.

But, in IE7 it appears to hit the return false, before the get finishes.

Code: [ Select ]
function handleLoading(data) {
        var $content = $("<div></div>").html(data);
        var $visualBadge = $("#visualBadge");
        
        $visualBadge.children("div").replaceWith($content);
        $visualBadge.find("a").click(handleClick);
    }
    
    function handleClick(evt) {
        var link = this;        
        var path = link.href;
        if(path.indexOf("#") != (path.length-1)){
            alert(path);
            $.get(link.href, handleLoading);             
            evt.preventDefault();
            return false;    
        }
    }
  1. function handleLoading(data) {
  2.         var $content = $("<div></div>").html(data);
  3.         var $visualBadge = $("#visualBadge");
  4.         
  5.         $visualBadge.children("div").replaceWith($content);
  6.         $visualBadge.find("a").click(handleClick);
  7.     }
  8.     
  9.     function handleClick(evt) {
  10.         var link = this;        
  11.         var path = link.href;
  12.         if(path.indexOf("#") != (path.length-1)){
  13.             alert(path);
  14.             $.get(link.href, handleLoading);             
  15.             evt.preventDefault();
  16.             return false;    
  17.         }
  18.     }


Using this line of code in place of my $.get above...I can see where the return data stops.
Code: [ Select ]
$.get(link.href, function(returned_data){alert(returned_data);});


Is there anyway to ensure the $.get completes before it runs the "return false"?
Image
Give a man a fish he eats for a day. Teach a man to fish he eats for a lifetime.
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post September 2nd, 2009, 12:07 pm

  • s15199d
  • Expert
  • Expert
  • User avatar
  • Joined: Feb 20, 2004
  • Posts: 524
  • Loc: NC, USA
  • Status: Offline

Post September 2nd, 2009, 12:21 pm

i think the answer is setting async to false for my get function, but i'm newbie to the point I'm not quite sure how to do that...

any pointers based on what I've already provided?
Image
Give a man a fish he eats for a day. Teach a man to fish he eats for a lifetime.
  • s15199d
  • Expert
  • Expert
  • User avatar
  • Joined: Feb 20, 2004
  • Posts: 524
  • Loc: NC, USA
  • Status: Offline

Post September 2nd, 2009, 12:45 pm

Maybe I should explain the intent of my code here.

I'm trying to override the onClick event of all <a> tags in my div id=virtualBadge

I want to make those links load their intended href in my div id=virtualBadge not in the window.top

Hopefully a little background will shed light on a possible solution
Image
Give a man a fish he eats for a day. Teach a man to fish he eats for a lifetime.
  • s15199d
  • Expert
  • Expert
  • User avatar
  • Joined: Feb 20, 2004
  • Posts: 524
  • Loc: NC, USA
  • Status: Offline

Post September 4th, 2009, 8:30 am

Ok...I've narrowed it down...I know where the failure is coming now.

In IE7 & IE6 the first alert, pops up all of the data. The second alert pops up empty.

Code: [ Select ]
function handleLoading(data) {
   alert(data);   
   var $visualBadge = $("#visualBadge");      
   $visualBadge.html(data)
   alert($visualBadge.html());
   $visualBadge.find("a").click(handleClick);
}
  1. function handleLoading(data) {
  2.    alert(data);   
  3.    var $visualBadge = $("#visualBadge");      
  4.    $visualBadge.html(data)
  5.    alert($visualBadge.html());
  6.    $visualBadge.find("a").click(handleClick);
  7. }


In Firefox 3.5 and Chrome it works fine.

Any idea how to fix this in IE7 & IE6?
Image
Give a man a fish he eats for a day. Teach a man to fish he eats for a lifetime.

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 143 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.