0

我有来自 ispring 的 html 数据,这是交互式菜单。我观察到我有本地存储(显然是上次查看的页面)。我也有日志系统,我需要将本地存储保存在 user_id 或 sessionid 中。我发现这个:https ://www.quora.com/Is-it-possible-to-get-localstorage-key-value-into-a-php-variable-If-so-how-can-we-do-它

我试过这个:

在 window.location 也许我需要做点什么,我不知道我是否朝着正确的方向前进

我在 indexmenu.html 中还有另一个代码:

我是编程初学者,我在森林里像瞎子一样,请帮助我

  <script>
  var value = localStorage.getItem('myKey');
 jQuery.post("indexmenu.html", {myKey: value}, function(data)
  {
  window.location.href='http://smartangielski.cba.pl/indexmenu/';
  });
   </script>
   <?php if(isset($_POST["user_id"])) { $value = $_POST['myKey']; }?>

'''''''''''''''''''''''

我需要在登录页面后,从上次记录的活动中获取本地存储数据

4

2 回答 2

0

您可以使用 Ajax 将 JS 数据发送到 PHP 页面。使用以下 coed 作为参考:

  //include jquery library too

  var myData = localStorage.getItem('myKey');

  $.ajax({ 
  url: 'http://smartangielski.cba.pl/indexmenu/', // URL of the PHP page where you want to send the variable
  type: 'POST',
  data: {myValue: myData },
  success: function(data) {
    //called when successful
    //Do something
  },
  error: function(e) {
    //called when there is an error
    console.log(e);
  }
}); 

在 PHP 页面中,您可以使用以下方式访问数据:

$myVal = $_POST['myValue'];

你可以在这里阅读更多

于 2019-04-23T12:11:58.487 回答
0

有可能从 ajax 发送到 indexmenu.html,因为只有在 html 中使用该页面的方法,我可以将 php 代码粘贴为 html 的一部分吗?我试试这个,但我不知道我应该在该领域使用哪个功能:“做某事”

于 2019-04-23T13:20:43.180 回答