I’m using jquery to send the code in some <pre> tags of my blog to an handler, that will replace these with a proper pastebin.com frame containing the formatted code.
I’m using an MD5 hash to map the code chunk to the pastebin corresponding translation in order to have just one paste bin for each code snippet.
Problem is that the string posted seems to change a little between IE and firefox, so I don’t have an exactly MD5 codification. For some reason problem appear only on the production server.
The jquery code is this:
$(function() {
$.each($('pre'), function(i, e) {
if (e.lang != '') {
$.ajax({
url: 'pastebin.ashx',
context: $(this),
data: {
data: $(this).text(),
lang: e.lang
},
success: function(t) {
if (t.indexOf('*error*') != 0) {
var h = Math.floor($(this).height() * 1.62) + "px";
$(this).replaceWith("<iframe src='http://pastebin.com/embed_iframe.php?i=" + t + "' style='border:none;width:100%;height:" + h + "'></iframe>")
}
}
});
}
});
});
Is there some reason the posted data can change from different browsers ?
EDIT
The problem does not happen with all the IE, same version 9.0.8112.16421 works on a machine, and not with another! I suppose the difference must be in the $(this).text(). Failing version seems to contain the text without carriage returns.
Ok, found the solution: using
html()instead oftext()fixed the problem: the only drawback of using html() is that the pre content is htmlEncoded, so I had to modify the handler, but the result we obtain seems ro be stable across browsers.