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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:29:03+00:00 2026-06-06T15:29:03+00:00

I am using HMVC codeigniter. I am trying to use jquery ajax first time.

  • 0

I am using HMVC codeigniter. I am trying to use jquery ajax first time. When i use POST then it gives undefined error while it response me the data while using GET.

         $.ajax({
          type: "POST",
          url: filelink+"cart/add_cart_item",
          data: {"product_id":id,"quantity":qty,"ajax":"1"},
          dataType: "json",
              success: function(msg){
           alert( "Data Saved: " + msg );
           },
               error: function(jqXHR, textStatus, errorThrown){ 
           alert(textStatus + " " + errorThrown);
            }
      });

What I have tried so far after googling and SO-ing-

  1. my file url location is accessible directly. I checked it. giving response.

  2. Firebug is giving 500 internal server error for the same file.

  3. Using Get is responding me back well

  4. added json in the datatype

controller function

  class Cart extends CI_Controller { // Our Cart class extends the Controller class

  function __construct()
     {
    parent::__construct();  
    $this->template->set('controller', $this);
     }

  function _remap()
    {
       $uri2 = $this->uri->segment(2);  
       if (is_numeric($uri2) OR $uri2 == FALSE) {
        $this->index(); 
       } else if ($uri2 == 'add_cart_item') {
        $this->add_cart_item();
       } else if ($uri2 == 'show_cart') {
        $this->show_cart();
       }
     }

function add_cart_item(){
      echo "asdfsadfdsf";
      exit; 
    }
  }

can anybody please help me out?

  • 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-06T15:29:05+00:00Added an answer on June 6, 2026 at 3:29 pm

    Managed to find the solution. The problem was due to CI_TOKEN which is sent with the FORM. That was absent and due to which POST method was giving 500 Internal server Error. I added following in my view file.

     <?php echo form_open_multipart(); ?>
     <?php echo form_close(); ?>
    

    and sent ci_token with the ajax post request.

     var ci_token = formObj.find('input[name=ci_token]').val();
     var qty = 1;
     var dataString = 'product_id='+ id + '&quantity=' + qty + '&ajax=' + 1 
     +'&ci_token=' +            ci_token;
    

    This solved the problem. I am not sure but this is called CSRF related some problem

    Thanks

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

Sidebar

Related Questions

Using Tank Auth for first time along with HMVC. In my application there are
I am using Codeigniter 1.7.2 and HMVC (https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/wiki/Home). I have these files and they
I'm using MVC pattern for web development. I use codeIgniter framework. I found http://fuelphp.com/
I'm using HMVC in CodeIgniter https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/wiki/Home How do I setup a controller that would
Using EF Code First I have an model object that has multiple properties that
I am trying to understand HMVC and how or if I should consider it
Using linq2sql I'm trying to take the string in txtOilChange and update the oilChange
Using the navigator.geolocation object in JavaScript. Trying to establish accurate ranges, but wondering exactly
Using Rails 3.2.0 with haml, sass and coffeescript: Basically I am trying to disable
Using jQuery, one can easily find out whether a particular element is visible using

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.