如何在没有任何用户事件的情况下将对象数组从javascript传递到php? [重复]

问题描述 投票:-1回答:1

我有一个JS清单。我想使用PHP将它保存在Mysql DB中,而没有任何用户事件。我无法将JS列表传递给php。

<script type="text/javascript">
// I have a javascript function that returns the output as below
    var result = 
      [
        {name: "Adam", age: "40", covid19: "positive"},
        {name: "Eve", age: "30", covid19: "negative"},
        {name: "David", age: "25", covid19: "positive"}
      ];
</script>

<?php
// To Do: Need to pass the result list above as an array,
//        so that I can save them individually in DB using simple for loop

   echo "<script>document.writeln(result);</script>";

  // This shows output like [object] [object] [object]....
?>
javascript php
1个回答
0
投票

需要Ajax,您才能将数据从前端传递到后端。 Followin是做到这一点的方法。

© www.soinside.com 2019 - 2024. All rights reserved.