【问题标题】:Add $_POST value to PHP array with every AJAX call在每次 AJAX 调用时将 $_POST 值添加到 PHP 数组
【发布时间】:2014-04-26 02:23:13
【问题描述】:
var itemtotal = parseFloat(words[1]).toFixed(2.0)*qty;

            $.ajax({

            type: 'POST',
            url: 'cartitem.php',
            data: {itemtotal:itemtotal},
            success: function(data){

                alert(data);

            }

我想将每个 AJAX 调用的值添加到 PHP 数组以供以后处理。我该怎么做?

【问题讨论】:

  • 如果您想通过多个 ajax 调用维护这些 post 请求中的值,您必须将它们存储在服务器端数据库、客户端本地存储或临时方式中,可能通过将值连接到 DOM 元素中(例如隐藏的输入框)
  • 有多种方法可以做到这一点,我猜 $_SESSION 将成为你的朋友。一切都取决于您真正想对这些值做什么。

标签: php jquery ajax arrays


【解决方案1】:

php:

if (isset($_POST['itemtotal'])) 
{

$array = [];

if (is_numeric($_POST['itemtotal'])) { 
//you need to do some validation here its just an example
 array_push($array, $_POST['itemtotal']);
}
}

希望对你有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多