Answers.Body: <p>This will be a environmental configuration issue. The only reason you could get that error is if your web server either isn't setting the global <code>$_SERVER['HTTP_X_REQUESTED_WITH']</code> variable or it is setting it and it's a value other than <code>XMLHttpRequest</code>.</p>
  
  <p><a href="https://github.com/yiisoft/yii/blob/1.1.17/framework/web/CHttpRequest.php#L679" rel="nofollow">https://github.com/yiisoft/yii/blob/1.1.17/framework/web/CHttpRequest.php#L679</a></p>
  
  <p>I'd check the server config and make sure there's nothing odd in your <code>.htaccess</code> files (if on Apache) that might be interfering.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-17T17:36:21.570Z
Answers.LastActivityDate: 2016-08-17T17:36:21.570Z
Answers.UserDisplayName: Brad Bell
Body: <p>I was working on a plugin with a hook on onBeforeSaveEntry in my dev environment (which is configured exactly like my live environment).</p>
  
  <p>I had a <code>var_dump</code> with an <code>exit</code> in the hook to check output of some variables on save. </p>
  
  <p>After deleting the <code>var_dump</code> and <code>exit</code> from the code the control panel now gives a unknown error on top of every page (which has an AJAX request).</p>
  
  <p>I've deleted any entry I've made today since the code changes but still no effect.</p>
  
  <p>After inspecting the logs the exception seems to be thrown in the BaseController class:</p>
  
  <pre><code>/**
   * Throws a 400 error if this isn’t an Ajax request.
   *
   * @throws HttpException
   * @return null
   */
  public function requireAjaxRequest()
  {
      if (!craft()-&gt;request-&gt;isAjaxRequest())
      {
          throw new HttpException(400);
      }
  }
  </code></pre>
  
  <p>Log output:</p>
  
  <pre><code>2016/08/15 21:05:16 [error] [exception.Craft\HttpException.400] exception 'Craft\HttpException' in /...myserverpath.../craft/app/controllers/BaseController.php:217
  Stack trace:
  #0 /...myserverpath.../craft/app/controllers/BaseElementsController.php(30): Craft\BaseController-&gt;requireAjaxRequest()
  #1 /...myserverpath.../craft/app/controllers/ElementIndexController.php(66): Craft\BaseElementsController-&gt;init()
  #2 /...myserverpath.../craft/app/framework/web/CWebApplication.php(281): Craft\ElementIndexController-&gt;init()
  #3 /...myserverpath.../craft/app/etc/web/WebApp.php(815): CWebApplication-&gt;runController('elementIndex/ge...')
  #4 /...myserverpath.../craft/app/etc/web/WebApp.php(285): Craft\WebApp-&gt;_processActionRequest()
  #5 /...myserverpath.../craft/app/framework/base/CApplication.php(185): Craft\WebApp-&gt;processRequest()
  #6 /...myserverpath.../craft/app/index.php(58): CApplication-&gt;run()
  </code></pre>
  
  <p>When I comment out the line:</p>
  
  <pre><code>throw new HttpException(400);
  </code></pre>
  
  <p>Everything is working fine.
  Because it seems to be an AJAX error, I tried another browser as well but the same error occurs.</p>
  
  <p>Anybody got any ideas?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-15T23:13:18.103Z
Comments.Text: What's the JavaScript code you're using to trigger the AJAX request?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-17T08:06:20.060Z
Comments.Text: None. JS is the standard control panel JS.
Comments.UserDisplayName: John Ripmeester
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-17T17:29:01.327Z
Comments.Text: Ahh sorry, misunderstood the question.  Will add an answer.
Comments.UserDisplayName: Brad Bell
Tags: <control-panel><ajax><error>
Title: Unknown error occurs on every AJAX call in CP
ThreadText: # Unknown error occurs on every AJAX call in CP
  
  (Asked by: username_0 on 2016-08-15)
  
  I was working on a plugin with a hook on onBeforeSaveEntry in my dev environment (which is configured exactly like my live environment).
  
  I had a `var_dump` with an `exit` in the hook to check output of some variables on save.
  
  After deleting the `var_dump` and `exit` from the code the control panel now gives a unknown error on top of every page (which has an AJAX request).
  
  I've deleted any entry I've made today since the code changes but still no effect.
  
  After inspecting the logs the exception seems to be thrown in the BaseController class:
  
  ```
  /**
   * Throws a 400 error if this isn’t an Ajax request.
   *
   * @throws HttpException
   * @return null
   */
  public function requireAjaxRequest()
  {
      if (!craft()->request->isAjaxRequest())
      {
          throw new HttpException(400);
      }
  }
  
  ```
  
  Log output:
  
  ```
  2016/08/15 21:05:16 [error] [exception.Craft\HttpException.400] exception 'Craft\HttpException' in /...myserverpath.../craft/app/controllers/BaseController.php:217
  Stack trace:
  #0 /...myserverpath.../craft/app/controllers/BaseElementsController.php(30): Craft\BaseController->requireAjaxRequest()
  #1 /...myserverpath.../craft/app/controllers/ElementIndexController.php(66): Craft\BaseElementsController->init()
  #2 /...myserverpath.../craft/app/framework/web/CWebApplication.php(281): Craft\ElementIndexController->init()
  #3 /...myserverpath.../craft/app/etc/web/WebApp.php(815): CWebApplication->runController('elementIndex/ge...')
  #4 /...myserverpath.../craft/app/etc/web/WebApp.php(285): Craft\WebApp->_processActionRequest()
  #5 /...myserverpath.../craft/app/framework/base/CApplication.php(185): Craft\WebApp->processRequest()
  #6 /...myserverpath.../craft/app/index.php(58): CApplication->run()
  
  ```
  
  When I comment out the line:
  
  ```
  throw new HttpException(400);
  
  ```
  
  Everything is working fine.
  Because it seems to be an AJAX error, I tried another browser as well but the same error occurs.
  
  Anybody got any ideas?
  
  **Tags:** control-panel, ajax, error
  
  > **Comments:**
  > **username_1**: What's the JavaScript code you're using to trigger the AJAX request?  
  > **username_0**: None. JS is the standard control panel JS.  
  > **username_1**: Ahh sorry, misunderstood the question.  Will add an answer.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-08-17. Score: 1
  
  This will be a environmental configuration issue. The only reason you could get that error is if your web server either isn't setting the global `$_SERVER['HTTP_X_REQUESTED_WITH']` variable or it is setting it and it's a value other than `XMLHttpRequest`.
  
  <https://github.com/yiisoft/yii/blob/1.1.17/framework/web/CHttpRequest.php#L679>
  
  I'd check the server config and make sure there's nothing odd in your `.htaccess` files (if on Apache) that might be interfering.
  
  
  ---
  
  