I'm running XMLHttpRequest
request like this:
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);
as you can see there's no name for parameter being passed.
now I want to read that JSON data inside ipsum
function of lorem
controller.
How can I do this? $this->input->post();
returns false :(
Use file_get_contents('php://input')
even though your turning a JSON Object into string your not assigning a key to the string, what so server side does not have an identifier for your string.
What you should do is:
req.send("json=" + data);
then in PHP use:
$this->input->post("json");
To receive data without the need of KV Pairs you can use stdin i suppose.
http://php.net/manual/en/wrappers.php.php
or even using a variable designed for this purpose:
$HTTP_RAW_POST_DATA
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With