简体   繁体   English

jQuery .load()回调不触发

[英]Jquery .load() callback not firing

Ive been struggling with this for hours now. 我已经为此努力了几个小时。 I can't figure out why my .load() callback is not firing. 我不知道为什么我的.load()回调不触发。 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();
    });
  }
});

hm, doesn't look like your alert would be hit right? 嗯,看起来您的警报似乎不会正确吗? You already return false before that. 在此之前,您已经返回false。

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() 无需从load()返回任何内容

Hey I tried removing the "return false" with no success.I think it's because .load() is asynchronous? 嘿,我尝试删除“ return false”没有成功。我认为是因为.load()是异步的?

Anyway, I got it to work using ".get" instead of .load and then selecting the contents with a variable. 无论如何,我使用“ .get”而不是.load使其工作,然后使用变量选择内容。 Thanks for the replies. 感谢您的答复。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM