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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:54:13+00:00 2026-06-15T07:54:13+00:00

Hi I’m currently learning about the AJAX in jQuery and now I’m trying to

  • 0

Hi I’m currently learning about the AJAX in jQuery and now I’m trying to use it in codeigniter. Now what happen is that I have a textbox wherein on keyup event it will call the function on my controller and it’s working anyways but the controller itself doesn’t get the current value of the textbox and it remains blank since I haven’t submitted the form yet so it can’t get the POST data. Well I don’t want to submit the form either since I only have one shot for submit and what I only want for this one is to check whether the event is already existing or not (for validation purposes). Here’s my code so far with added comments for better viewing.

View:

<div>
<form>
<table border="0">
    <tr>
        <td>
            <title>Name: </title>
        </td>
        <td>
            <input id="name" type="text" name="eventname" />
        </td>
        <td>
            <div id="name1"></div>
        </td>
    </tr>
</table>

<script type="text/javascript" src="<?php echo $base; ?>javascripts/jquery-1.8.2.min.js">
     </script>
<script type="text/javascript" src="<?php echo $base; ?>javascripts/ajax.js">
     </script>

</form>
</div>

The controller:

<?php

class Login extends CI_Controller {

    public function __construct()
    {
        parent::__construct();
        $this->load->model('test_model');
    }

    public function view()
    {
        $data['base'] = $this->config->base_url();

        //CHECK IF THE $PAGE VIEW IS EXISTING
        if ( !file_exists('test/views/pages/test_form/test_form.php'))
        {
            // IF PAGE DOESN'T EXISTS SHOW 404 ERROR
            show_404();
        }

        //FOR THE TITLE PART
        $data['title'] = ucfirst('Test'); 

        $this->load->view('templates/header', $data);
        $this->load->view('pages/test_form/test_form', $data);
        $this->load->view('templates/footer', $data);

    }

    public function message()
    {
        //this one will access database
        echo $this->test_model->check_event($this->input->post('eventname'));
        //username doesn't get the current value on keyup unlike the AJAX part
    }

}

The model:

<?php
class Test_model extends CI_Model {

    public function __construct()
    {
        $this->load->database();
    }

    public function check_event($test_input)
    {
        if($test_input==null){
            return "True";
        }
        else
            return "False";
    }

}

and the AJAX:

$('#name').keyup(function() { //LISTENER FOR BUTTON CLICK BASED ON ID button ON THE PHP PAGE
    var name = $('#name').val();

    $.ajax({ //STARTS AJAX
    type: 'POST',
    url: '/CodeIgniter_2.1.3/index.php/login/message/', //THIS PAGE IS LOADED ON THE AJAX data IS THE CONTENTS ON THE PAGE NOTE COMMA SEPARATED VALUES
    data: 'name='+name,
    statusCode: { //THE STATUS FOR THE PAGE. NOTE THIS IS CASE SENSITIVE
        404: function(){ //IF 404 ERROR OCCURS THIS MESSAGE WILL BE DISPLAYED
            $('#name1').text('Page not found');
        }, //NOTE COMMA SEPARATED VALUES
        202: function(){ //IF 202 SHOW THIS TEXT
            $('#name1').text('Please wait');
        }
    }, //NOTE COMMA SEPARATED VALUES
    success: function(data){ //IF PAGE EXISTS OR FOUND THE data FROM THE GIVEN PAGE WILL BE LOADED AND PASSED
        $('#name1').html(data); //THE content ID ON THE PHP PAGE WILL CONTAIN ALL THE html data OF THE GIVEN PAGE
    }
    });
});

Well sorry for this AJAX part. it’s full of comments which I don’t think necessary It’s just a note for me to quickly review the codes. 🙂 Is there’s something wrong with my codes or do I need to use some function to retrieve the data?

  • 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-06-15T07:54:15+00:00Added an answer on June 15, 2026 at 7:54 am

    you are posting the data as “name”….

    check your ajax

    data: 'name='+name,   // this is data that is posted by ajax..you are posting it with a name as "name"
    

    so u have to get the input post as “name” and not “eventname”…

    either you have to rename the data’s name data: 'name='+name, to data: 'eventname='+name,

    OR

    replace this

    echo $this->test_model->check_event($this->input->post('eventname'));
    

    with this

    echo $this->test_model->check_event($this->input->post('name'));
    

    in your controller and it should work….

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

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.