title: Can't modify response in a Magento event observer, even though observer is firing
body: <p>I'm attempting to use an observer to modify the response of the add to cart controller action, but only in the context of an AJAX request.</p>
  
  <p>My observer <strong>is</strong> called and my JS is retrieving data fine, I have verified this by putting a <code>die()</code> in my observer function <code>cartAdd()</code> and verifying the response developer console, which I am using to see the result of my response from Magento. So JS isn't the issue here.</p>
  
  <p>My primary problem is that I can't seem to modify the response through the normal functions. I get the request by using <code>$observer-&gt;getEvent()-&gt;getControllerAction()-&gt;getResponse()</code> and then make changes to it by <code>setHeader()</code>, or <code>setBody()</code>, or any other function that modifies the response, but there is absolutely no effect to the response!</p>
  
  <p>Does anybody have any clue as to why I'm not able to modify the response in my observer?</p>
  
  <p>In /app/code/local/mynamespace/mymodule/etc/config.xml:</p>
  
  <pre><code>&lt;frontend&gt;
  ....
      &lt;events&gt;
          &lt;controller_action_predispatch_checkout_cart_add&gt;
              &lt;observers&gt;
                  &lt;mymodule_cart_add&gt;
                      &lt;type&gt;singleton&lt;/type&gt;
                      &lt;class&gt;mymodule/observer&lt;/class&gt;
                      &lt;method&gt;cartAdd&lt;/method&gt;
                  &lt;/mymodule_cart_add&gt;
              &lt;/observers&gt;
          &lt;/controller_action_predispatch_checkout_cart_add&gt;
      &lt;/events&gt;
  &lt;/frontend&gt;
  </code></pre>
  
  <p>In /app/code/local/mynamespace/mymodule/Model/Observer.php:</p>
  
  <pre><code>public function cartAdd(Varien_Event_Observer $observer)
  {
      $controllerAction = $observer-&gt;getEvent()-&gt;getControllerAction();
      if($controllerAction-&gt;getRequest()-&gt;isAjax()) {
          $response = $controllerAction-&gt;getResponse();
          // I've even tried using:
          // $response = Mage::app()-&gt;getResponse();
          $response-&gt;setHeader('HTTP/1.1','403 Forbidden'); //using this because i will need it in my final code and it will make it immediatly obvious the response has been changed
          $response-&gt;setHeader('Content-type', 'application/json');
          $response-&gt;setBody('hello world!!!!');
          // this is to stop the product from being added to the cart
          $controllerAction-&gt;setFlag('', Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true);
      }
  }
  </code></pre>
  
  <p><em>Please note: I know this code isn't going to at all AJAXify adding to cart (which is my end goal). At the moment I am just trying to resolve this issue</em></p>
  
  <p>I end up just getting the contents of the page that you would end up on as a result of running an add to cart action:</p>
  
  <p><img src="https://i.stack.imgur.com/4cdIv.jpg" alt="An example of the data I am seeing in the console, as shown to me by my JS code"></p>