jQuery AJAX POST请求:服务器中为空

时间:2018-01-08 11:43:43

标签: php jquery ajax

我发送这个AJAX请求,但是在服务器中数组是空的。有帮助吗?在Firebug中,我可以看到请求正在发送。

  $.ajax({
    type: 'POST',
    url: 'presupuesto_guardar.php',
    data: { 'data': '1' },
  })

//PHP
var_dump($_POST); //this is empty

正在发送请求:

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:0)

如果没有,请写成功函数返回响应,请按以下代码执行

$.ajax({
    type: 'POST',
    url: 'presupuesto_guardar.php',
    data: { 'data': '1' },
    success : function(response){
        console.log(response);
    }
})

请尝试php://input获取您的帖子数据,而不是$_POST

php://input将返回标题

之后的所有原始数据
$post = file_get_contents('php://input');

echo json_encode($post);
相关问题