在codeigniter控制器中获取整个帖子体

Dav*_*vid 4 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.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);
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,传递的参数没有名称.

现在我想在控制器的ipsum功能里面读取JSON数据lorem.我怎样才能做到这一点?$this->input->post();返回false :(

Mor*_*eng 7

使用 file_get_contents('php://input')