Read ajax response headers?

How can I grab information from the response headers from within an
jQuery ajax callback?

I have an object, "data", containing IDs to different items I'd like
to build a detailed list with. I need to grab these details by sending
a request to a server--one for each item.

The issue I'm running into, is the response from the server contains
half the information I need in the body of the response, and the other
half in the headers. I can't figure out a bullet-proof way of reading
the headers at the same time as the body...

Here's a look at what I'm working with:

function index(data) {

        for (var i = 0; i < data.length; i++) {

                $.ajax({

                        type: 'GET',
                        url: 'http://domain.com/',
                        data: 'this=that',
                        success: function(data) {

                                /* Here I want to create a list item out of the 
data returned in
the body and headers */

                        }, complete: function(XMLHttpRequest, textStatus) {

                        }, error: function() {

                        }

                });

        }

}

I've tried saving the $.ajax as a variable, and
using .getResponseHeader('name'), but that only works sometimes, and
other times returns "Error: INVALID_STATE_ERR: DOM Exception 11",
which apparently means the headers aren't ready to be read. I've tried
this both in the success and complete function.

Any help would be incredibly awesome!

Reply via email to