如果满足条件,则阻止用PJAX替换html内容

时间:2016-03-24 10:30:52

标签: javascript jquery

我有 pjax:beforeReplace 的以下事件监听器来检查来自服务器的内容,如果满足条件,则不显示任何内容和

$(document).on("pjax:beforeReplace", function(e, contents) {
   var $contentBeforePut = $(contents);

   if(conditionHere) {
       // here I want to prevent put html content, I tried with:
       location.reload(true);
   }
}

但不起作用,意味着放置了html内容,可见,然后重新加载页面。

$(document).on("pjax:end", function () { 
    // the code is executed even I put location.reload in beforeReplace event 
});

我想在用pjax放入内容之前重新加载页面,怎么做?

1 个答案:

答案 0 :(得分:0)

尝试

$(document).on("pjax:beforeReplace", function(e, contents) {
   var $contentBeforePut = $(contents);

   if(conditionHere) {
       // here I want to prevent put html content, I tried with:
       return false; 
   }
}

来自 https://github.com/defunkt/jquery-pjax/issues/427

的参考资料