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 551987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:27:08+00:00 2026-05-13T11:27:08+00:00

The following codes works without jquery. I insert data but it does not update

  • 0

The following codes works without jquery.

I insert data but it does not update with ajax.
I have to refresh to show the update.

Could anyone have a look at it and point out what I am doing wrong please?

Thanks in advance.

Jquery is this one.

$(document).ready(function(){
//global vars
var inputUser = $("#nick");
var inputMessage = $("#message");
var loading = $("#loading");
var messageList = $(".content > ul");

//functions
function updateShoutbox(){
    //just for the fade effect
    messageList.hide();
    loading.fadeIn();
    //send the post to shoutbox.php
    $.ajax({
        type: "POST", 
        url: "index.php/admin/messages/getShoutBox", 
        // data: "action=update",
        complete: function(data){
            loading.fadeOut();
            messageList.html(data.responseText);
            messageList.fadeIn(2000);
        }
    });
}
//check if all fields are filled
function checkForm(){
    if(inputUser.attr("value") && inputMessage.attr("value"))
        return true;
    else
        return false;
}

//Load for the first time the shoutbox data
updateShoutbox();

//on submit event
$("#form").submit(function(){
    if(checkForm()){
        var nick = inputUser.attr("value");
        var message = inputMessage.attr("value");
        //we deactivate submit button while sending
        $("#send").attr({ disabled:true, value:"Sending..." });
        $("#send").blur();
        //send the post to shoutbox.php
        $.ajax({
            type: "POST", 
            url: "index.php/admin/messages/insertShoutBox", 
            data: $('#form').serialize(),
            complete: function(data){
                messageList.html(data.responseText);
                updateShoutbox();
                //reactivate the send button
                $("#send").attr({ disabled:false, value:"Shout it!" });
            }
         });
    }
    else alert("Please fill all fields!");
    //we prevent the refresh of the page after submitting the form
    return false;
});
});

I have the following controller.
controllers/admin/messages.php

function getShoutBox(){
  $data['title'] = "getshoutbox";
    $data['main'] = 'admin_home';
      $data['messages']=$this->MMessages->getMessages();
    $this->load->vars($data);
    $this->load->view('dashboard'); 

}

function insertShoutBox(){
    $data['title'] = "insertshoutbox";
    $data['main'] = 'admin_home';
    $this->MMessages->updateMessage();
    $data['messages']=$this->MMessages->getMessages();
    $this->load->vars($data);
    $this->load->view('dashboard'); 

}

View is this one.

<form method="post" id="form" action="index.php/admin/messages/insertShoutBox" >
        <label>User</label>
        <input class="text user" name="user" id="nick" type="text" MAXLENGTH="25" />
        <label>Message</label>
        <input class="text" id="message" name="message" type="text" MAXLENGTH="255" />
        <input id="send" type="submit" value="Shout it!" />

    </form>
    <div id="container">
        <ul class="menu">
            <li>Shoutbox</li>
        </ul>
        <span class="clear"></span>
        <div class="content">
            <h1>Latest Messages</h1>
            <div id="loading"><img src="images/general/loading.gif" alt="Loading..." /></div>

            <?php
            foreach ($messages as $key => $list){

            print_r ($list);
            }
            ?>

        </div>
    </div>
  • 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-13T11:27:08+00:00Added an answer on May 13, 2026 at 11:27 am

    A few things look suspicious to me.

    Are you sure this URL is correct?

    url: "index.php/admin/messages/getShoutBox",
    

    Also, this line looks a bit suspect:

    if(inputUser.attr("value") && inputMessage.attr("value"))  
    

    Have you check what happens if if both values are zero? (You could use the .val() function instead of .attr("value") as well)

    Even if it does work, a simple return instead your if/else would have sufficed:

    return (inputUser.attr("value") && inputMessage.attr("value"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 397k
  • Answers 397k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer void noop() { } May 15, 2026 at 3:19 am
  • Editorial Team
    Editorial Team added an answer Simply add a unique constraint: Alter Table TableName Add Constraint… May 15, 2026 at 3:19 am
  • Editorial Team
    Editorial Team added an answer If it were me, I would avoid modifying the scalar… May 15, 2026 at 3:19 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.