Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在codeigniter控制器内获取整个柱体_Php_Ajax_Codeigniter - Fatal编程技术网

Php 在codeigniter控制器内获取整个柱体

Php 在codeigniter控制器内获取整个柱体,php,ajax,codeigniter,Php,Ajax,Codeigniter,我正在运行XMLHttpRequest请求,如下所示: var data = JSON.stringify({ name : "123", id : 12 }); window.console.log("Submitting: " + data); var req = new XMLHttpRequest(); req.open('POST', "http://localhost/index.php/lorem/ipsum", true); req.setRequestHead

我正在运行
XMLHttpRequest
请求,如下所示:

var data = JSON.stringify({
    name : "123",
    id : 12
});

window.console.log("Submitting: " + data);
var req = new XMLHttpRequest();
req.open('POST', "http://localhost/index.php/lorem/ipsum", true);
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.onreadystatechange = function() {
    if (  req.readyState==4) {
        window.console.log( "Sent back: " + req.responseText );
    }
}
req.send(data);
正如您所看到的,传递的参数没有名称

现在我想读取
lorem
控制器的
ipsum
函数中的JSON数据。
我该怎么做<代码>$this->input->post()返回false:(

即使您将JSON对象转换为字符串,但没有为字符串分配键,因此服务器端没有字符串的标识符

你应该做的是:

req.send("json=" + data);
然后在PHP中使用:

$this->input->post("json");
要接收数据而不需要KV对,我想您可以使用stdin

或者甚至使用为此目的设计的变量:


$HTTP\u RAW\u POST\u DATA

使用
文件获取内容('php://input“)

谢谢您的回复!我知道我可以这样做。我想知道是否有其他方法,没有标识符。可能是接收http请求正文的某种方法。是的,当然有,
fopen(”php://stdin“,“r”)
阅读原始输入,但这不是前进的方向。我认为我做得晚了,但内容类型应该是application/json(是的,我知道这不会有任何影响)