I'm making a post request using fetch in my codeigniter project. The request looks like this
fetch('myurl/mycontroller', {
method: 'POST',
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
testdata: 123,
})
}).then((res) => {
console.log(res);
}).catch(console.log);
My controller looks like below
class MyController extends CI_Controller
{
public function mycontroller()
{
$data = $this->input->post('testdata');
return $data . " is the passed data.";
}
}
But the data isn't getting passed to my controller. I echoed out $_POST and it gave me an empty array. Any idea what I'm doing wrong? I'm using codeigniter 2 (which I know is very old now)