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

  • Home
  • SEARCH
  • 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 4039394
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:36:19+00:00 2026-05-20T12:36:19+00:00

So… thanks to one of stackoverflow users I tried to implement this fancy feature

  • 0

So… thanks to one of stackoverflow users I tried to implement this fancy feature into my existing Codeigniter application…

In my View I have this:

<script type="text/javascript">
$(function() {
    $(".submit_op").click(function() {
        var dataString = $("#op_form").serialize();
        var url = "<?php echo site_url('submit/insert_data'); ?>";
        $.ajax({
            type: "POST",
            url: url+"/"+dataString,
            data: dataString,
            cache: false,
            success: function(html){
                //$("div#op").prepend(html); //PROBLEM HERE???
                $("div#op").prepend("<div>TEST</div>");
                $("div#op div:first").fadeIn("slow");
                //$("#debug").append("<font color=green><b>OK!</b></font> : " + dataString + "<br/>");
            },
            error: function(html){
                //$("#debug").append("<font color=red><b>ER!</b></font> : " + dataString + "<br/>");
            }
        });
        return false;
    });
});
</script>

<div id="debug"></div>

<?php
//here goes some data from db... newly added div should go in top of other divs
foreach ($some_data_sent_from_controller as $var) {
    echo "<div id=\"op\">";
    echo "<table width=\"100%\" border=\"0\">";
    //showing data
    echo "</table>";
    echo "</div>";
}

echo "<form action=\"#\" id=\"op_form\">";
//some clickable stuff...
echo br().form_submit('submit', 'OK', 'class="submit_op"');
echo "</form>";

In my Controller I have a function which handles data sent from View:

function insert_data($input) {
    $this->load->model('blah_model');
    //processing serialized data and sending it to corresponding tables via Model
    $this->blah_model->add_to_table($some_data);
    $this->blah_model->add_to_another_table($some_other_data);

}

And the Model is not a biggy 🙂

function add_to_table($data){
            //processing data...
    $insert = $this->db->insert('my_table', array('array_which_contains_actual_data'));
    if ($insert == TRUE) {
        return TRUE;
    } else {
        return FALSE;
    }
}
//etc.

As far as I can tell, my problem is not in my M-V-C pattern, since every time I submit a form the data is correctly inserted in all possible tables in my relational db… But the newly added row just won’t show up unless I refresh a page.

I think that I’m doing something wrong inside of my jQuery.ajax lines… If I run my script with this line $("div#op").prepend("<div>TEST</div>"); and when I submit a form, I get desired result – text TEST shows up on top of my page every time I submit… But if I change that line to $("div#op").prepend(html); nothing show up until refreshing…

What am I doing wrong here??

Thanks a lot for any help!

  • 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-20T12:36:20+00:00Added an answer on May 20, 2026 at 12:36 pm

    wow, this was probably pretty lame from me… But in the end I figured out that I have to echo out my result in controller, not return it… So when I change the function in my controller into

    function insert_data($input) {
        $str = "<div>KILLROY WAS HERE!</div>";
        echo $str; // <----- !!!!!!
    }
    

    I can see a message on my page…

    Now to other things… Thanks for self-brainstorming 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an element like this: <span class=tool_tip title=The full title>The ful&#8230;</span> This seems
what about this one: I want to format the currentTime displayed by a videoPlayer
CGI.escapeHTML is pretty bad, but CGI.unescapeHTML is completely borked. For example: require 'cgi' CGI.unescapeHTML('&#8230;')
I am currently running into a problem where an element is coming back from
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
English is not my native language. I need a software to spellcheck and correct
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I have been making a wordpress template. i got stuck at some place... the
I have the following problem: I am given a tree with N apples, for
I have a MySQL query: SELECT px.player, px.pos, px.year, px.age, px.gp, px.goals, px.assists ,

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.