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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:18:44+00:00 2026-05-14T03:18:44+00:00

I trying to make my first AJAX with JSON call using jQuery and CodeIgniter.

  • 0

I trying to make my first AJAX with JSON call using jQuery and CodeIgniter.
But for some weird reason it’s not working.

The jQuery code:

var item = "COOL!";
$.post("http://192.168.8.138/index.php/main/test", { "item" : item },
         function(data){
            alert(data.result);
         }, "json");

The CodeIgniter code:

<?php
class main extends Controller {
   function test() {
      $item = trim($this->input->post('item'));
      $array = array('result' => $item);
      echo json_encode($array);
   }
}
?>

I tried to access the http://192.168.8.138/index.php/main/test page manually and it seems to be working, I got: {"result":""}

I also tried to use Firebug to see XMLHttpRequest but saw nothing.

I have no idea what am I doing wrong… Need help really badly.
Thank you.

  • 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-14T03:18:44+00:00Added an answer on May 14, 2026 at 3:18 am

    You may need to set the HTTP content type to application/json to get this to work:

    <?php
    class main extends Controller {
       function test() {
          $item = trim($this->input->post('item'));
          $array = array('result' => $item);
          header('Content-Type: application/json',true);
          echo json_encode($array);
       }
    }
    ?>)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make two ajax requests in parallel using jQuery like this:
I'm trying to make my first web service client for the eBay API using
I am trying to make my first AJAX Control and I get error. I
I'm trying to make an ajax call to grab session data to insert into
Trying to make a web service call to an HTTPS endpoint in my Silverlight
I'm trying to make the case for click-once and smart client development but my
I am trying to remove Details from http://localhost:1985/Materials/Details/2/Steel but some how my route doesn't
I use to work with the animation on jquery but never ajax, so it's
Alright, I'm trying to make an AJAX Chat system that polls the chat database
I'm trying to make a proof of concept website, but I want perfect degradation.

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.