Welcome Guest, Not a member yet? Register   Sign In
IS_AJAX constant being ignored - how come?
#1

[eluser]JohnnyAction[/eluser]
I'm learning AJAX w CI 1.7 right now from this tutorial: http://www.weblee.co.uk/2009/06/07/simpl...er-part-1/

So far, things are good. I'm in the 2nd part, where it explains to add this line of code to the bottom of your constants.php file to check for AJAX activity.

Code:
define('IS_AJAX', isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');

Then here's an example of the function I'm playing with:

Code:
// Task function
public function task() {
  if(IS_AJAX) {
   echo 11;
  }else{  
   echo "Direct access not allowed";
  }
}

When I run this function directly from a URL, it still echo's 11. For some reason it isn't reading the IS_AJAX constant. If I change the code to this:

Code:
// Task function
public function task() {
  if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
   echo 11;
  }else{  
   echo "Direct access not allowed";
  }
}

It works fine.
What am I doing wrong with my constants.php?
And yes, I realize there's an $this->input->is_ajax_request() in CI 2.0, but I'm comfortable with CI 1.7. Unless there's a major reason to upgrade, I'll stick with it.




Theme © iAndrew 2016 - Forum software by © MyBB