Created
January 20, 2010 23:50
-
-
Save mackstann/282440 to your computer and use it in GitHub Desktop.
Content negotiation via XMLHttpRequest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This will change every link on a page with a *type* attribute | |
// to go through XMLHttpRequest, setting the Accept header, so | |
// that content negotiation can be used to get an alternate | |
// content type without having to put the content type in the URL. | |
$("a[type]").click( | |
function() { | |
$.ajax({ | |
url: $(this).attr("href"), | |
async: false, | |
xhr: function() { | |
var x = new XMLHttpRequest(); | |
x.setRequestHeader("Accept", $(this).attr('type')); | |
return x; | |
} | |
}); | |
return false; | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment