Skip to content

Instantly share code, notes, and snippets.

@mackstann
Created January 20, 2010 23:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mackstann/282440 to your computer and use it in GitHub Desktop.
Save mackstann/282440 to your computer and use it in GitHub Desktop.
Content negotiation via XMLHttpRequest
// 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