Search code examples
twitter-bootstrapbootstrap-table

jquery push not works in $.get method


in this example:

function detailFormatter(index, row) {
        var html = [];
        $.each(row, function (key, value) {
        if(key == 'id')
        {
            html.push(key);
            $.get("function/conversation/message/"+value, function(data, status){
                html.push(data);
                alert(data);
            });


        }

        });
        return html.join('');
    }

first html.push(key) works.

alert works.

but secondhtml.push(data) not works.

what is my wrong?


Solution

  • I think your main problem will be that $.get is asynchronous operation. So if your result on return html.join(''); is not what you expected don't be surprised, because the operation might not be finished at that time.