Rectangle 27 0

Your ajax data must include the value of the hidden CSRF token field. This is the part that gets submitted with the standard form action but is missing when you do the ajax.

Thank you for this! As you can see in my last comment I had just found out on this. The problem I still have is that I also want to make some test-files for this controller which works outside CI. Therefor I cannot use any of CI's functions to create such csrf-token and pass it to the post data. I can however disable csrf protection on that uri, but I don't know if that is safe.

FWIW, this CSRF data is also required when using the remote method in jQuery Validate. Basically, anything that uses ajax to access a CodeIgniter URL must include the value of the hidden CSRF token.

@BenurRoptire, the CSRF token is there for security, so I'm never going to tell you it's "safe" to remove it - that's a matter of opinion. Research the meaning of CSRF so you can make your own informed decision.

Thank you all for the help! I have now excluded the uri from the csrf protection. One other problem I still have is that the Ajax-request does not appear to be using the same session. The controller that is requested needs the same session as the one you use to start the request.

php - Ajax call on CodeIgniter controller results in 403 Forbidden - S...

php jquery ajax codeigniter
Rectangle 27 0

The solution to this is to make an ajax call to the server, you can have a method on your controller which calls your codeigniter method. This divides your php call and your client side call.

If you are inserting something into the database, you should use the ajax post method.

function myInsert() { 
  $('input[name=r_maybe].r_box').each(function(){ 
    if( $(this).prop('checked') ){ 
      var value = $(this).prop('value');
      $.post("controllername/functionname", { value: value }, function(data) { 
        alert(data); // Returned message from the server
      }); 
     } 
  }); 
}

Thanks for the tip. Yes, I am trying to insert something into the database, so does that mean I should not use your $.post but should instead be using $.ajax ?

$post is a shorthanded call for using post on $ajax , you can use either, but specify type post if you use $ajax

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

php - Codeigniter method inside javascript loop - Stack Overflow

php javascript codeigniter
Rectangle 27 0

After further researching I was able to determine that there are two modes to php running: cgi or cli. Upon testing with php -v in shell I confirmed it was configured for cli, but running the same with a Cron job I saw the result being php running as cgi.

/usr/local/bin/php /home/overstoc/www/admin/index.php cron update

I assume the default php that the Cron job is calling has a configuration for cgi where the server share is cli.

Can anyone detail where the php that is called by default is located and why it would runs as cgi? Also, why does this differ from calling php in shell?

php - How can I debug a Codeigniter Cron job that only runs the defaul...

php codeigniter cron command-line-interface
Rectangle 27 0

has a semi colon in the url. change it to:

should be

var url="148.209.25.135/evaluacionAdmin/index.php/prueba";// delete extra semicolon

The standard CI config has an allowed character list for the URI. You can modify the regex to accept semi colons as well, but in this case it looks like you put that semi colon in there by accident.

Thanks a lot, it solved the issue

php - Ajax 400 Bad Request upon calling a CodeIgniter controller with ...

php jquery ajax codeigniter
Rectangle 27 0

$result=$this->db->query($qry);
 foreach($result->result() as $row){
   $data[]=$row;
 }
return $data;
return $result->result_array();

That should solve your problem. You can check result_array() section of CodeIgniter documentation.

php - Codeigniter: how to call multiple model function in single contr...

php mysql codeigniter
Rectangle 27 0

$result=$this->db->query($qry);
 foreach($result->result() as $row){
   $data[]=$row;
 }
return $data;
return $result->result_array();

That should solve your problem. You can check result_array() section of CodeIgniter documentation.

php - Codeigniter: how to call multiple model function in single contr...

php mysql codeigniter
Rectangle 27 0

This is not how you call a controller method in CodeIgniter.

You should have something like this for calling a method:

yourController->test(); ?>
ajax->test();

If you are accessing this method by clicking a link in your view page, then write like this:

<a href="<?php echo base_url(); ?>index.php/ajax/test">Drink up me hearties, Yo ho!</a>

php - codeigniter unable to call function in the controller want to us...

php ajax codeigniter
Rectangle 27 0

Try putting functions like get_some_data() on a library, then you'll be able to include and call them from every controller and every function without problems, sending the results formatted in a partial view (static case) or back to the browser after an ajax call.

Always remember to deal with data only on models and libraries. This way you'll not have to worry about conficting controllers.

// main/index
$this->load->library('your_library');
$data['foo'] = $this->your_library->get_foo();

// controller2/get_some_ajax_data
$this->load->library('your_library');
echo $this->your_library->get_foo() || '';

php - CodeIgniter: invoking multiple controllers in one call - Stack O...

php model-view-controller architecture codeigniter