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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:59:12+00:00 2026-05-31T04:59:12+00:00

After tons of coding, I feel like I am finally wrapping my head around

  • 0

After tons of coding, I feel like I am finally wrapping my head around AJAX, JSON, and CI to a degree.

However, I feel I have hit one final snag. Below is my code:

HTML

<div id="structures">
    <h1>Build</h1>
    <form name="buildForm" id="buildForm" method="POST" action="<?php echo base_url(); ?>/ajax/index/">
        <select name="buildID" class="buildClass">
        <option value="0" selected="selected" data-skip="1">Build a Structure</option>
<?php foreach ($structures as $structure_info): ?>
    <option name='<?php echo $structure_info['str_name'] ?>' value='<?php echo $structure_info['str_id'] ?>' data-icon='<?php echo $structure_info['str_imageloc'] ?>' data-html-text='<?php echo $structure_info['str_name'] ?><i>
        <?php echo $structure_info['timebuildmins'] ?> minutes<br><?php echo $structure_info['buy_gold'] ?> gold</i>'><?php echo $structure_info['str_name'] ?></option>
<?php endforeach ?>
        </select>
        <div id="buildSubmit">
            <input id ="btnSubmit" class="button" type="submit" value="Submit"/>
        </div>
    </form>
</div>

Here I am simply building my form.

AJAX/JS

$(function(){
    $("#buildForm").click(function(e, buildID){
        e.preventDefault();
        var frm = $(document.buildForm);
        var dat = JSON.stringify(frm.serializeArray());
        alert("I am about to POST this:\n\n" + dat);
        $.post(
            frm.attr("action"),
            dat,        
        function(response) 
        {  
            alert(response);
        }  
    );
});
});

Model Function

public function insert_build()
   {    
      $str_id = $this->input->post(dat);
      print_r($str_id);
   }

I created a new controller class extension “Ajax” and function “index” This simply calls my model “insert_build.” It was my workaround to take the .js file off the page and keep it in the header.

Anyway. When I hit the submit button, it successfully alerts the JSON output. Though after it is passed to the controller->model, it doesn’t seem to catch anywhere. I assume I’m doing it wrong, but can not figure out what.

Thanks for the 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-31T04:59:13+00:00Added an answer on May 31, 2026 at 4:59 am

    Try a couple things here.

    After var frm = $(document.buildForm); try alerting it’s action value

    alert(frm.attr("action"));
    

    to make sure your $.post is actually getting a valid URL.

    Then try changing your insert_build function to just print out what it’s receiving. You shouldn’t be calling $this->input->post(dat); because you won’t have a post named dat.

    public function insert_build()
    {
        print_r($_POST);
    }
    

    EDIT

    You’ll need to pass the json string as a url param. Try

    $.post(frm.attr("action"), {data:dat}, function(response) 
        {  
            alert(response);
        });
    

    And then changing your PHP to

    public function insert_build()
    {    
        $str_id = $this->input->post('data');
        print_r(json_decode($str_id));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been wrestling with this for a few days and after tons of
I have a simple Web Form with code like this: //... //tons of text
After seeing tons of web site using modal window with a nice expansion animation
So after extensive research and tons of jQuery and Javascript solutions I simply could
After deploying WCF server (svc) on my Server, I have got this message when
I have an object that I alloc/init like normal just to get a instance.
After surfing through tons of documentation on the web it seems that the iPhone
I have tons of lines in a file and I wanna know if sed
It seems to be a widely asked questions and after having read tons of
I updated my project, written tons of code and after that i updated again.

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.