doulian7305 2017-05-18 19:58
浏览 114
已采纳

在javascript函数中通过session或localstorage将var调用到另一个页面

Im to trying to send javascript response to another page by using localstorage or by using session but im unable to get response here is javascript fun below eg
page1.php

  function data(responseData) {
alert(responseData.dataValue);  eg:name   //here im getting data    
alert("Total = "+responseData.dataValue);
      $("#submit-link").attr('href',"https://example.com/paymentdata.php?totalScore="+total);
}


page2.php
Here i called the link

    <button id="process">Process</button>
<br />
<a href="#" id="submit-link">links</a> // i want that name here 

I have tried i got nothing. All i want from page1.php data get in page2.php data i have tried through session also no result

  • 写回答

1条回答 默认 最新

  • dsvtnz6350 2017-05-18 20:06
    关注

    By using the browser local storage you can pass any data between any pages in your website. If you have more complex data like an object you have to stringify/parse to get it to work, but otherwise a string or integer will work fine.

    window.localStorage.setItem('key', 'a string value');
    window.localStorage.setItem('key', JSON.stringify(YourValueAsObject));
    
    var getValueFromLS = window.localStorage.getItem('key');
    var getValueFromLSParsed = JSON.parse(getValueFromLS);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器