1

I tried to access an id from a URL "myfolder/mycontroller/mymethode/123" which I call into an AJAXcall.

I cannot access them, in "mycontroller" under the "mymethode". I tried to output $_GET, $_POST, $this->input->get(), $this->input->post(), but all array are empty.

In the Controller/mycontroller I have this

public function mymethode($listid=false)
{
      echo "listid: $listid";
      print_r($_GET);
      print_r($_POST);
      print_r($this->input->get());
      print_r($this->input->post());
}

The Ajax call is this and is ok with Status 200.

$.ajax({
                          url: http://mydomein.com/myfolder/mycontroller/mymethode/123,
                          type: "POST",
                          method: 'post',
                          data: form + "&" + additional_data + csrfName + "=" + csrfHash, 
                          dataType: 'json',
                          cache: false,                         
                         success: function(res){...

If I tried to open the URL directly, I have the same problem.

What can the reason for it be?

Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85
relo80
  • 245
  • 2
  • 13
  • Even your `$listid` is empty? Have a look at your `config.php` and check your `$config['uri_protocol']` setting. You may need to change this to get things to work. – gen_Eric Feb 04 '21 at 17:53
  • $config['uri_protocol'] = 'REQUEST_URI'; on other pages it works, so i think there must something special with this!? – relo80 Feb 04 '21 at 17:57
  • Try to `var_dump($_SERVER)`, that should show you the value of `REQUEST_URI` (and other things) to see if the `uri_protocol` is right. – gen_Eric Feb 04 '21 at 17:58
  • is this HMVC ?? – Abdulla Nilam Feb 06 '21 at 07:08

1 Answers1

0

Use this (if this is not HMVC)

in route.php

# You may need first route since you're accepting null on method
$route['mymethode] = 'mycontroller/mymethode';
$route['mymethode/(:num)'] = 'mycontroller/mymethode/$1';

In AJAX

url: http://mydomein.com/mymethode/123,

Make sure your sites run without index.php

In controller

public function mymethode($listid=null)
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85