0

I am using a simple POST to one of my controllers using Ajax, however in my in development tools it seems to never be able to find the controller. I get the error

POST http:// localhost:8888/time.php/checkit 404 (Not Found) 

I'm not sure if this has something to do with the routes of CodeIgniter or the .htaccess file.

My Ajax call looks like:

  $("#submittodo").click(function () {
      $.ajax({
          url: 'time.php/checkit',
          type: "POST",
          data: {name: $(this).val()},
          success: function (data) {
           alert(data);
          }
      });
  });
1
  • 1
    can you visit http:// localhost:8888/time.php/checkit in your browser? for code igniter that looks like a really strange url. are you trying to hit /time/checkit ? could you elaborate on whats going wrong here? not much to go on. Commented Jul 11, 2014 at 19:51

3 Answers 3

1

Yo need to include base_url() on your url:

$("#submittodo").click(function () {
  $.ajax({
      url: '<?php echo base_url()?>time.php/checkit',
      type: "POST",
      data: {name: $(this).val()},
      success: function (data) {
       alert(data);
      }
  });
});

Also, check your config file, if you have $config['csrf_protection'] set to TRUE, you also need to get csrf token like this:

var post_data = {
    'name': $(this).val(),
    '<?php echo $this->security->get_csrf_token_name(); ?>' : '<?php echo $this->security->get_csrf_hash(); ?>'
};

$("#submittodo").click(function () {
  $.ajax({
      url: '<?php echo base_url()?>time.php/checkit',
      type: "POST",
      data: post_data,
      success: function (data) {
       alert(data);
      }
  });
});
Sign up to request clarification or add additional context in comments.

Comments

0

If you are using CI, you need to follow the URL structure, e.g: domain. com/controller/method.c In your case:

URL : '<?Php echo base_url( ) ?>time/checkit',

Mind that there isn't no .Php appended to the controller name. And an absolute URL is used.

Comments

0

try like this

 $("#submittodo").click(function () {
      $.ajax({
          url: '<?Php echo base_url(); ?>time/checkit',
          type: "POST",
          data: {name: $(this).val()},
          success: function (data) {
           alert(data);
          }
      });
  });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.