Php 在服务器端找不到ajax json数据

Php 在服务器端找不到ajax json数据,php,jquery,ajax,codeigniter,Php,Jquery,Ajax,Codeigniter,我试图从客户端的jquery向codeigniter控制器发送一些数据。我有: var data = { "value" : value, "message" : message }; console.log(postData); $.ajax({ type: "POST", url: "my_controller/my_function", data: data, dataType:'json', success: function

我试图从客户端的jquery向codeigniter控制器发送一些数据。我有:

var data = {
    "value" : value,
    "message" : message
};

console.log(postData);

$.ajax({
    type: "POST",
    url: "my_controller/my_function",
    data: data, 
    dataType:'json',
    success: function(){

    }
});
这似乎工作正常,因为我可以在chrome开发工具中看到正确的post参数。在我的codeigniter控制器中,我尝试过:

echo 'post' . $_POST['value'].' '.$_POST['message'];

$postData=$this->input->post('value');

var_dump($postData); exit;
我得到:

Message: Undefined index: value
Message: Undefined index: message

boolean(false)
$\u POST
数组为空


我怎样才能解决这个问题?感谢您的帮助

基于您的代码,我得到了一个运行良好的:

js:

在php文件php.php中:

<?php

echo json_encode($_POST);

?>

因此,我在浏览器的控制台中得到了以下信息:


对象{value:“value”,message:“message”}

您只需按照代码操作即可

var data = {
    value : value,
    message : message
};    

$.ajax({
    type: "POST",
    url: '<?php echo base_url(); ?>my_controller/my_function',
    data: data, 
    dataType:'json',
    success: function(responseFromServer){
        console.log(responseFromServer);
    }
});
在返回任何东西之前,只需使用以下代码

 header('Content-Type: application/json', true);
 echo json_encode($postData); 

现在,您在客户端找到了一个对象数组。

尝试删除数据类型行,因为jQuery检测到数据类型本身非常好。您是否实际设置了值和消息变量?这并不能说明这一点。
$postData= $this->input->post('value');
$message= $this->input->post('message');
 header('Content-Type: application/json', true);
 echo json_encode($postData);