如何使用ajax$.post获取发送到服务器端的数据

how do I get the data I send to server side using ajax $.post?

本文关键字:服务器端 数据 获取 何使用 ajax post      更新时间:2023-09-26

我使用$.post将表单数据作为由对象文字组成的数组发送到process.php,如下所示

$('#form').submit(function(e){
        var my_result = JSON.stringify(array);// array is the array where I   store my object literals. It contains only object literals
        alert(my_result);
        $.post('process.php', my_result, function(answer) {
            alert('success'); 
        })
        .fail(function() {
            alert('failure');
        });
    });

数据已经发送,但我不知道如何从服务器端访问数据并将其解压缩以存储在数据库中。有人知道怎么做吗?我读了之前的帖子,但它们对我没有任何帮助,反而让我更加困惑。

您可以使用$_POST global:访问数据

$server_side_my_result_var = $_POST['my_result'];