JavaScript的history.back损失的搜索结果 [英] javascript history.back losses the search result

查看:162
本文介绍了JavaScript的history.back损失的搜索结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

页答:

  $(文件)。就绪(函数(){
    bindData();
});

传播bindData(){
    $('#searchbtn')绑定(点击,函数(){信息搜索结果();});
}
功能信息搜索结果(){
 Ajax调用...
}
 

第一个HTML:

 <输入类型=按钮ID =searchbtn/>
 

页B详细--->将此页来自页中选择一个特定的搜索结果,搜索列表后

 < A HREF =JavaScript的:history.back();>返回< / A>< BR />
 

现在,当我回到页面AI能看到我的搜索标准的,因为他们选择,但结果事业部已经一去不复返了。我所试图做的是我想要的搜索列表留在页回来。 我想我可以在这里做的是一些如何再次调用searchbtn点击事件,当页面回来因此该列​​表会-再次出现。谁能告诉我如何触发searchbtn click事件只有当页面来自页B.背部或指向我这样做的正确的方式.. 谢谢

解决方案

 函数bindData(){
    VAR chkinput1 = $(输入:复选框[名称= X]:选中)的长度。
    。VAR chkinput2 = $(输入:复选框[名称= Y]:选中)的长度;

    如果(chkinput1大于0&安培;&安培; chkinput2大于0){
       搜索结果();
     }
    $('#searchbtn')绑定(点击,函数(){信息搜索结果();});
    }
 

我知道这是实现这一结果的最糟糕的方式,但我认为不是使用任何其它插件添加的复杂性,我们将与这个去了。如果其他人正在寻找同样的问题,让我再告诉你一遍,这是不是最好的做法,因为在返回回历史,我们呼吁在搜索结果中再根据复选框的缓存的输入选择和生成整个Ajax调用再次显示该列表。在第一次请求我缓存列表和设置可调过期所以它不是随时采取翻盘,因此每个人都愉快地生活。

Page A:

$(document).ready(function () {
    bindData();
});

function bindData() {
    $('#searchbtn').bind('click', function () { SearchResult(); });
}
function SearchResult() {
 ajax call...
}

Page A HTML:

<input type="button" id="searchbtn" />

Page B Details---> this page comes after selecting a specific search result from page A search list

    <a href="javascript:history.back();">Back</a><br />

Now when I go back to the Page A I can see my search criteria's as they were selected but the result Div is gone. What I am trying to do is I want the search list to stay when the Page comes back. I think what I can do here is some how call the searchbtn click event again when the page comes back so the list will come-up again. Can anyone tell me how to fire the searchbtn click event only when the page comes back from Page B. or point me in the right way of doing this.. Thanks

解决方案

    function bindData() {
    var chkinput1 = $("input:checkbox[name=x]:checked").length;
    var chkinput2 = $("input:checkbox[name=y]:checked").length;

    if (chkinput1 > 0 && chkinput2 > 0) {
       SearchResult();
     }
    $('#searchbtn').bind('click', function () { SearchResult(); });
    }

I know this is the worst way to achieve this result but I think instead of using any other plugins to add complexity we will go with this for now. If anyone else is looking for the same question let me tell you again this is not the best practice as on returning back to the history we are calling the search result again depending upon the cached input selection of checkboxes and generating the whole ajax call again to display the list. On the first request I am caching the list and setting sliding expiration so its not taking anytime to comeback and so everyone lives happily.

这篇关于JavaScript的history.back损失的搜索结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆