我正在运行这样的 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);

如您所见,没有传递参数的名称。

现在我想在 ipsum Controller 的 lorem 函数中读取 JSON 数据。
我怎样才能做到这一点? $this->input->post(); 返回 false :(

最佳答案

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

关于php - 在 codeigniter Controller 中获取整个帖子正文,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4339616/

10-11 03:31
查看更多