jQuery Get + Post returned headers

This snippet allows you to use the response headers from a $.get and $.post function.

Particularly useful if you return a PHP response with additional information for jQuery to handle. i.e: Custom Header: Could not connect to database.

$(function() {

	var result = $.get('index.php', function(data) {

		console.log ( result.getAllResponseHeaders() );
		console.log ( result.getResponseHeader('Date') );




Date: Tue, 18 Sep 2012 11:24:40 GMT
Content-Encoding: gzip
X-Powered-By: PHP/5.3.5
Connection: Keep-Alive
Content-Length: 2713
Server: Apache/2.2.17 (Win32) PHP/5.3.5
Vary: Accept-Encoding
Content-Type: text/html
Keep-Alive: timeout=5, max=98
Tue, 18 Sep 2012 11:24:40 GMT