I am wondering if there's a way to get the last post's revision source without these steps. Is there a more direct way?

  • I need to ask the Stack Exchange API to give me the API site parameter
  • I need to get revisions of current posts via the API
  • I need to get that revision from http://"+document.domain+"/revisions/"+revision_guid+"/view-source, and parse the response (jQuery $(response).filter("pre");)

The body field from /revisions/ (in the second step) just gives HTML response, which is not what I'm looking for.

For those wanting to know WHY do I want to do this, it's because I want to show post source under the current post.

  • 2
    Shouldn't this type of question be asked on stackapps.com/questions ? (I'm not sure)
    – Mat
    Apr 22, 2012 at 11:22
  • @Mat I wasn't actually sure, too
    – Martin.
    Apr 22, 2012 at 11:23
  • If its not already there I can userscript it :) Apr 22, 2012 at 12:25
  • @Martin: I know, it was a bad meme joke :/ Apr 22, 2012 at 14:45
  • @Martin: Being a programmer site, wouldn't you expect http://meta.stackoverflow.com/revisions/130017/-1 to point to http://meta.stackoverflow.com/revisions/130017/3? That would be a great way to implement this--negative-relative revision numbering. :) Apr 22, 2012 at 14:47
  • For my script I found it simplest to copy the source out of the /edit/ page, but that's not so great if you need to handle locked/uneditable posts.
    – Jeremy
    Apr 22, 2012 at 16:17
  • @Twilight actually, no. What a great idea! Just a simple OT question: why does $(response).filter("pre") work in my code to find the raw source but $("pre", response) nor $(response).find("pre") doesn't? (gives me an empty array)
    – Martin.
    Apr 23, 2012 at 4:22

1 Answer 1


@Twilight gave me an amazing idea of using edit page for this simple purpose.

This gets a source of question and answers:

$(".question, .answer").each(function() {
    var id = $(this).attr("data-questionid");
    if (!id) {
        id = $(this).attr("data-answerid");
    $.get("http://"+document.domain+"/posts/"+id+"/edit-inline", function(t) {  
        // $(t).find("textarea").val() is the source
  • Just for future readers, one drawback that Twilight noted: "not so great if you need to handle locked/uneditable posts". I myself wonder if this would somehow increase some counters on the servers, like indicators that someone started editing. But I guess such counters would actually be based on true editing the text (like when a draft is saved). And I don't know of any current functionality that would use such counters to start with.
    – Arjan
    Apr 28, 2012 at 10:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .