CodeIgniter Forums
output->set_header does not work in 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: output->set_header does not work in AJAX (/showthread.php?tid=33609)



output->set_header does not work in AJAX - El Forum - 09-01-2010

[eluser]tokyotech[/eluser]
Why does setting headers only work for a normal page, but not for an AJAX?

Code:
public MyClass extends Controller {
   // This loads a normal page. In Firebug, I look at the
   // page's headers in the net tab and I see "myParam" was
   // properly set.
   public function index() {
      $this->load->view('myView');
      $this->output->set_header('myParam: myValue');
   }

   // When I attempt to do the same for a request meant for
   // AJAX, it doesn't work. Firebug does not show "myParam"
   // When I inspect the headers in the console tab.
   public function ajaxAttemp1() {
      echo 'my text';
      $this->output->set_header('myParam: myValue');
   }

   // Here, I try to set the headers before I echo anything.
   // It still does not work.
   public function ajaxAttemp2() {
      $this->output->set_header('myParam: myValue');
      echo 'my text';
   }
}