Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7670177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:45:44+00:00 2026-05-31T15:45:44+00:00

First sorry, im a really big begginer, i dont really understand something. I am

  • 0

First sorry, im a really big begginer, i dont really understand something.

I am building a small caht form my users, and the inserting is okay.

I would like to that when i insert my chat message, after that the inserted message would slide down, and im a bit stuck with it.

my jquery

$('#chat_submit').on('click', function(e){
            e.preventDefault();
            var res = {
                'msg' : $('#chat_msg').val(),
            }

            $.ajax({
                type: 'POST',
                url: '<?php echo base_url(); ?>main/send_chat',
                data: res,
                dataType: 'json',
                success: function(data, html){
                    $('#chat_msg').removeAttr('value');

                }   
            });
            return false;
        });

html and php

<div id="content">
    <h2>Chat</h2>
            <div id="chatbox">
            <?php foreach ($chat as $ch): ?>
                <?php 
                    echo '
                        <div class="chat_post">
                            <span class="chat_time">'.date('H:i', strtotime($ch->added)).'</span>
                            <a href="'.base_url().'profile/user/'.$ch->uid.'" class="chat_name">'.$ch->first_name. " " .$ch->last_name.': </a>
                            <span class="chat_msg">'.$ch->msg.'</span>
                        </div>
                    ';
                ?>
            <?php endforeach; ?>
            </div>
            <?php echo form_open(base_url() . "main/send_chat"); ?> 
        <div id="feed_wrapp">   
            <input type="text" name="msg"  id="chat_msg">
            <input type="submit" value="Küldés" class="submit" id="chat_submit">    
        </div>
    <?php echo form_close(); ?> 
</div>

i tried numerous ways but im totally clueless, could please someone point out what i am missing?

send chat function in my controller

function send_chat() 
    {

        $this->load->model('user/chat_model');  
        if($this->input->is_ajax_request()) 
        {
            $this->chat_model->chat_insert();   
        }   
        //redirect(base_url());
    }

and the insert in my model

function chat_insert()
    {
        $chat = array(
            'uid' => $this->session->userdata('uid'),
            'msg' => $this->input->post('msg')
        );

        $this->db->insert('pf_chat_post', $chat);
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T15:45:45+00:00Added an answer on May 31, 2026 at 3:45 pm

    first modify your CI controller and model functions like this

    function send_chat()
    {
    $succeed = false;
    $this->load->model('user/chat_model');
    if ($this->input->is_ajax_request()) {
        $succeeded = $this->chat_model->chat_insert();
    }
    if ($succeeded) {
        echo '<div class="chat_post">
                            <span class="chat_time">' . date('H:i') . '</span>
                            <a href="' . base_url() . 'profile/user/' . $this->session->userdata('uid') . '" class="chat_name">' . $this->input->post('first_name') . " " . $this->input->post('last_name') . ': </a>
                            <span class="chat_msg">' . $this->input->post('msg') . '</span>
                        </div>';
    }
    }
    
    function chat_insert()
    {
    $chat = array(
        'uid' => $this->session->userdata('uid'),
        'msg' => $this->input->post('msg')
    );
    $this->db->insert('pf_chat_post', $chat);
    return ($this->db->affected_rows() > 0);
    }
    

    and in your form add two hidden inputs named “first_name” and “last_name”

     <input type="hidden" name="first_name" value="database value" />
     <input type="hidden" name="last_name"  value="database value" />
    

    and then in your success function in $.ajax call add this :

    $("#chatbox").append(data);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all I'm sorry but I'm a really big beginner. I dont really
First sorry if its a stupid guestion but im a really big beginner. I
At first sorry for my really bad title! If you have a better title
first of all I am sorry for the bad description, but I really don't
First of all Sorry for the really long post, now And this is my
First of all I'm really sorry for asking such a basic thing, I know
First, I really sorry for my poor english... Now I use iScroll to make
First of all, I want to say sorry for this very big question, but
First let me say I really sorry for asking a question about facebook. I'm
I'm new to Objective-c, so sorry if I'm missing something really obvious. I'm currently

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.