Take the 2-minute tour ×

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){
        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) {

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') }    
share|improve this question

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
Yargg! Thanks mate. Such a simple solution! –  grep Jul 19 '12 at 15:31

Your Answer


