hi i'm building one basic website from codeigniter, i'm basically laravel developer but for some reason had to get look with codeigniter, here i'm making an ajax call with the codeigniter view page, and i'm following https://makitweb.com/send-ajax-request-codeigniter/ this tutorial, and here is i tried code
$.ajax({
type: "POST",
url: "<?php echo base_url('messages/msgnotification'); ?>",
data: "userid=" + '<?php echo $this->uri->segment(2); ?>',
success: function(msg){
console.log(msg);
}
});
and this is in controller
class Messages extends CI_Controller {
function __construct() {
Parent::__construct();
$this->load->model('Chat_notification_model');
$getSession = $this->session->userdata;
public function index() {
}
// get unread chat
function msgnotification(){
// POST data
$postData = $this->input->post();
echo $postData;
// get data
$data = $this->Chat_notification_model->get_chat_notification($postData);
echo json_encode($data);
}
and here is my modal
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Chat_notification_model extends CI_Model {
function __construct() {
Parent::__construct();
}
function get_chat_notification($postData=array()){
$response = array();
if(isset($postData['user_id']) ){
// Select record
$this->db->select('count(*)');
$this->db->where('msg_id', $postData['user_id']);
$records = $this->db->get('Messages');
$cnt = $records->row_array();
$response = $cnt['count(*)'];
}
return $response;
}
?>
i referred below SO links
- Codeigniter ajax call 404 error on hosting
- Codeigniter - Error on Ajax call (404)
- Codeigniter Ajax gets 404 Error
but none are helped me from above, any helps are thank you