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?

  • What's the JavaScript code you're using to trigger the AJAX request?
    – Brad Bell
    Commented Aug 15, 2016 at 23:13
  • None. JS is the standard control panel JS. Commented Aug 17, 2016 at 8:06
  • Ahh sorry, misunderstood the question. Will add an answer.
    – Brad Bell
    Commented Aug 17, 2016 at 17:29

1 Answer 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.


I'd check the server config and make sure there's nothing odd in your .htaccess files (if on Apache) that might be interfering.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.