0

Ive been struggling with this for hours now. I can't figure out why my .load() callback is not firing. Can anyone shed any light on this. Thanks for any help.

The load it's self works fine.

window.addEventListener('popstate', function(event) {

  var linkplus = ((event.state) + ' #container'); //contents

  if((event.state)==null){
    $("#maincontainer").load("index.php #container", "null" , function(){
        return false;
        //  why is this not working ???  //
        alert("contents loaded");
    });
  }else{
    $("#maincontainer").load(linkplus, function(){
        return false;
        $("#container").hide().delay(0).fadeIn(400);
        project_nav();
    });
  }
});
enemetch
  • 492
  • 2
  • 8
  • 21
jstleger0
  • 105
  • 1
  • 14

3 Answers3

1

hm, doesn't look like your alert would be hit right? You already return false before that.

Jason Dam
  • 390
  • 1
  • 8
1

When you return from a function, you return

$("#maincontainer").load("index.php #container", "null" , function(){

    return false;  // YOU RETURNED HERE, NOTHING BELOW IS EXECUTED

    alert("contents loaded");

});

There's no need to return anything from load()

adeneo
  • 312,895
  • 29
  • 395
  • 388
0

Hey I tried removing the "return false" with no success.I think it's because .load() is asynchronous?

Anyway, I got it to work using ".get" instead of .load and then selecting the contents with a variable. Thanks for the replies.

    $.get( "index.php", function( data ) {
        var content = $(data).find('#container').html();
        $("#container").html(content);
        alert("contents loaded");
    });
jstleger0
  • 105
  • 1
  • 14