CodeIgniter Forums
controller functions that are only accessible to jquery or ajax - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: controller functions that are only accessible to jquery or ajax (/showthread.php?tid=55772)



controller functions that are only accessible to jquery or ajax - El Forum - 11-08-2012

[eluser]xeroblast[/eluser]
as i was reading this thread : http://ellislab.com/forums/viewthread/229428/ .. a question pops in my mind..

if making function in controller to be private and not be accessible in the URL. is there a way to send data via ajax and its URL is not accessible by the browser but only ajax?

i tried making a private function but ajax cant send the data to the URL i give.


controller functions that are only accessible to jquery or ajax - El Forum - 11-08-2012

[eluser]Mirge[/eluser]
Keep your function accessible so that you can query it via AJAX, and in the controller itself, test if it's an ajax call via is_ajax_request(). See manual here, very bottom: http://ellislab.com/codeigniter/user-guide/libraries/input.html

An example might be something like:

Code:
public function get_cities()
{
     if(! $this->input->is_ajax_request())
          show_404();

     // Otherwise, proceed as usual!
}



controller functions that are only accessible to jquery or ajax - El Forum - 11-09-2012

[eluser]xeroblast[/eluser]
this is what im looking for..


controller functions that are only accessible to jquery or ajax - El Forum - 11-09-2012

[eluser]Mirge[/eluser]
Happy to help.