0
I’m trying to send information that is in the javascript code block to my controller, but I’m not sure how to capture the information in my controller.
Follow view Javascript code:
<script type="text/javascript">
fetch('http://localhost/page.com.br/public/id_notification', {
method: "POST",
id: 1515
})
.then(function(response) {
return console.log(response);
});
</script>
Route file:
$route['id_notification'] = 'post_notification/insert_id_post_notification';
My controller:
<?php
class Post_notification extends CI_Controller
{
public function insert_id_post_notification()
{
$teste = $_POST['id'];
var_dump($teste);
}
}
?>
Name of my controller: post_notification.
I want to capture the id with value 1515 in my controller. Test value Thank you very much, everyone.
Your fetch is wrong: https://googleweblight.com/i?u=https://github.com/github/fetch/issues/635&hl=en-BR take a look
– novic
Hello friend! really was incorrect, I changed and it was as follows
– Felippe Sousa
fetch('http://localhost/app.realizaconstructa.com.br/public/id_notification', { method: "POST", body: 1515 }) . then(Function(Response) { Return console.log(Response); });
– Felippe Sousa
Now I need to know how to capture this 1515 value in my controller :/
– Felippe Sousa
thus:
fetch('localhost/app.realizaconstrutora.com.br/public/id_notification', { method: "POST", body: 'source=1515', headers: {
 "Content-Type": "application/x-www-form-urlencoded"} }) .then(function(response) { return console.log(response); });
and then in your code you search forsource
so it will work in your backend...– novic