I have made a quick ajax driven page for pasting some text and running the yuicompressor. The output works just great, however, when I send the stdout back to my page, I have issues with the data cutting off at a <
character. For example, when I run the compressor on this:
function Enum(values){
for( var i = 0; i < values.length; ++i ){
this[values[i]] = i;
}
return this;
}
I get a compressed version, no problem. Now, when I send this to my page like such:
exec(command, function(err, stdout, stderr) {
console.log(stdout);
res.writeHead(200, {'content-type': 'text/plain'});
//res.write(decodeURIComponent(escape(stdout)));
//res.write(qs.escape(stdout));
res.write(stdout);
res.end('\n');
});
This always causes the data getting sent to be cut off at the <
resulting in:
function Enum(a){for(var b=0;b
The console.log(stdout)
displays perfectly, so it's not until its sent to the client that it gets cut off.
When I attempted the encoding, I was able to get the entire output to my page all escaped out, but decoding it on the frontend resulted in the same issue of chopping it off.
Here's the ajax call:
if(ready) {
$.ajax('/get' + args + '/', {
type: 'GET',
dataType: 'text',
success: function(data) { $('pre').html(data) },
error: function() { console.log('error retrieving data') }
});
}
It looks like your difficulty is that you're telling jQuery to use a block of JavaScript as HTML, and it's "cutting off" at the first HTML metacharacter, <
. The content of a pre
tag is still HTML, just whitespace is treated differently. Call $('pre').text(data)
and you should be fine.