CodeIgniter Forums
ajax call to controller function outside root - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: ajax call to controller function outside root (/showthread.php?tid=66352)



ajax call to controller function outside root - Marcel - 10-13-2016

hi all

my application folder sits about the root
how can i call a controller function from ajax ?

Code:
$('#editabout').click(function() {
  
          

  $.ajax({
    type: 'get',
    url: '../application/controllers/auth_public/editabout',
    dataType: 'html',
    success: function (html) {
    
      $('#testdiv').html(html);
    }
  });
});

thanks


RE: ajax call to controller function outside root - PaulD - 10-13-2016

The url you use is exactly like a normal link url, index.php will pick it up and convert it to wherever you application root is or follow any routing rules etc

PHP Code:
url'<?php echo site_url('auth_public/editabout'); ?>'

Alternatively you can hard code it in if your js is not contained in a view. Or you can set your base_url in a data attribute somewhere are read it in.


RE: ajax call to controller function outside root - Marcel - 10-13-2016

(10-13-2016, 11:19 AM)PaulD Wrote: The url you use is exactly like a normal link url, index.php will pick it up and convert it to wherever you application root is or follow any routing rules etc

PHP Code:
url'<?php echo site_url('auth_public/editabout'); ?>'

Alternatively you can hard code it in if your js is not contained in a view. Or you can set your base_url in a data attribute somewhere are read it in.

you are a genius thanks

is it goot to put in root to hide 'auth_public'

$route['editabout'] = 'auth_public/editabout';