Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将多个搜索结果之一发送到另一个页面_Javascript_Jquery_Ajax - Fatal编程技术网

Javascript 将多个搜索结果之一发送到另一个页面

Javascript 将多个搜索结果之一发送到另一个页面,javascript,jquery,ajax,Javascript,Jquery,Ajax,我有一个页面userLanding.jsp 当用户执行搜索时,页面将给出多个结果。 我需要检查所选的动态结果(到目前为止已成功), 现在的问题是我需要将所选div的数据发送/传输/检索到另一个页面 我该怎么做 下面是我用来检查所选结果的代码 $('.demo-card-wide').click(function(){ article = $(this).text(); }); $(document).on('click', '.demo-card-wide', function(){

我有一个页面
userLanding.jsp
当用户执行搜索时,页面将给出多个结果。 我需要检查所选的动态结果(到目前为止已成功), 现在的问题是我需要将所选div的数据发送/传输/检索到另一个页面

我该怎么做

下面是我用来检查所选结果的代码

$('.demo-card-wide').click(function(){
    article = $(this).text(); 
});

$(document).on('click', '.demo-card-wide', function(){
    alert("clicked on result!!");
    var id = this.id;
    window.location = "http://localhost:8080/CarPool/test.jsp#"+id;  
});

由于您正在重定向到一个新页面,该页面的值要设置为URL的哈希值,因此您可以使用
window.location.hash
在页面加载时访问该值(尽管我不信任超过该值的数据,因为加载后页面可能会更改该值)

如果需要进一步持久化数据,可以研究
localstorage
或服务器端解决方案


下面是我将如何做的(使用
localstorage
):

使此代码可用于两个页面:

  /**
   * Feature detect + local reference for simple use of local storage
   * Use this like:
   * if (storage) {
   *    storage.setItem('key', 'value');
   *    storage.getItem('key');
   * }
   *
   */
  var storage;
  var fail;
  var uid;
  try {
    uid = new Date;
    (storage = window.localStorage).setItem(uid, uid);
    fail = storage.getItem(uid) != uid;
    storage.removeItem(uid);
    fail && (storage = false);
  } catch (exception) {}
  /* end  Feature detect + local reference */
在第一页上有以下内容:

  $(document).on('click', '.demo-card-wide', function() {
    if (storage) {
      alert("clicked on result!!");
      storage.setItem('article-id', this.id);
      window.location = "http://localhost:8080/CarPool/test.jsp";
    } else // some error message
  });
在第二页上,执行以下操作:

  $(function() {
    if (storage) {
      var id = storage.getItem('article-id');
      // do something with id...
    }
  });

您试图检索的
id
是什么值?您使用的是什么服务器语言?听起来您需要去阅读一些教程。id是我要发送/传输到另一个页面的选定div的id我正在使用JSP,但大多数编码都在jquery、ajax中,您希望在
window.location=”页面上获取此值http://localhost:8080/CarPool/test.jsp#“+id将您发送到?让我试试这个@bleeted0d
  $(function() {
    if (storage) {
      var id = storage.getItem('article-id');
      // do something with id...
    }
  });