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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:05:45+00:00 2026-05-30T21:05:45+00:00

Im trying to learn how to use JSON from within codeigniter. I’m trying to

  • 0

Im trying to learn how to use JSON from within codeigniter. I’m trying to use a model to run the ajax code, but its not working.

I need to learn how to pass variables through to the model, and back out; or, if thats incorrect, I need to learn the correct process. The below is my code.

HTML

<div id="structures">
    <h1>Build</h1>
    <form name="buildForm" id="buildForm" method="POST">
        <select name="buildID" class="buildClass">
        <option value="0" selected="selected" data-skip="1">Build a Structure</option>
    <option name='Town Center' value='1' data-icon='../img/structures/tc.png' data-html-text='Town Center<i>
        500 minutes<br>50000 gold</i>'>Town Center</option>
    <option name='Barracks' value='2' data-icon='../img/structures/barracks.png' data-html-text='Barracks<i>
        25 minutes<br>1500 gold</i>'>Barracks</option>
    <option name='Dragon Roost' value='3' data-icon='../img/structures/droost.png' data-html-text='Dragon Roost<i>
        200 minutes<br>5000 gold</i>'>Dragon Roost</option>
    <option name='Mage Hall' value='4' data-icon='../img/structures/mage.png' data-html-text='Mage Hall<i>
        40 minutes<br>300 gold</i>'>Mage Hall</option>
    <option name='Test Lab' value='6' data-icon='../img/structures/testlab.png' data-html-text='Test Lab<i>
        1 minutes<br>10 gold</i>'>Test Lab</option>
        </select>
        <div id="buildSubmit">
            <input id ="btnSubmit" class="button" type="submit" value="Submit"/>
        </div>
    </form>
</div>

Here is my ajax/js/json
I’m trying a very simple example. I’d like to post the value of the OPTION above (1-6) to the model function insert_build. I don’t know if its doing it, as I can’t really think of a good way to test it. However, I would assume if it returned anything, I would be alerted. I am not.

$(function(){
    $(".button").click(function(e, value){
        e.preventDefault();

        $.ajax({
        type: "POST",
        url: "<?php $this->structure_model->insert_build() ?>",         //the script to call to get data          
        str_id: value,
        dataType: 'json',                //data format      
        success: function(data)          //on receive of reply
            {
                alert("success!");
            } 
        });
 });
});

The model code

 public function insert_build()
        {
            $str_id = $this->input->post('str_id');
            echo " TESTING $str_id";
        }

Any help would be greatly appreciated. Why doesn’t this work? I am still trying to understand the fundamentals of Codeigniter and JSON / JS.

Thanks

  • 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-30T21:05:46+00:00Added an answer on May 30, 2026 at 9:05 pm

    The url: you’re setting in your javascript is the actual function you’re wanting to call when the ajax is submitted. You’ll need to have a controller in place that actually calls that function e.g.

    url: "<?php echo base_url(); ?>/structure/insert/?str_id=" + $('#buildID').val(),
    

    Also, setting dataType: to json means you’re expecting what’s returned from your function to be encoded as json.

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

Sidebar

Related Questions

I am trying to learn CodeIgniter to use for a shopping site, but I
I'm trying to learn how to use managed/unmanaged code interop, but I've hit a
I am trying to learn and use html5 and have a basic layout but
I'm trying to learn how to use the Control.Parallel module, but I think I
I'm trying to learn how to use CURL and Json to access data sent
I am trying to learn how to use JSON and writing a simple program
Trying to learn how to use JSON and parse the json data.i am using
I am trying to learn to use mercurial by pushing onto Google code. I
I'm trying to learn to use SDL for a little game I'm writing ,
I am trying to learn and use an SDK for a vendor's product. Unfortunately,

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.