views:

1018

answers:

1

I am making an ajax request from a jquery script to one of my ajax controllers in codeigniter. This process works fine when using data type json. However, when I want to send xml back from the server, the jquery documentation says that the server must specify a MIME type of text/xml. How do I do this with codeigniter. My ajax call looks like this:

   $.ajax({
    type: "POST",
    url: siteUrl + "index.php/ajax_controller/test",
    dataType: "xml",
    success: testSuccess
   });
+1  A: 

You can specify a content type header using the following code. You could put it at the top of your controller method in CI:

header("Content-Type: text/xml");

It must be before any output starts, so use it before you call your first $this->load->view().

zombat
Perfect, thanks
Clayton