0

I have the following function using the CodeMirror.

function app() {
    jQuery.get('http://localhost:2748/foo.txt', function (data) {
        alert(data);
    });
    alert(data);
    editor.setValue(data);
}

The alert displays the textfile data but when I assign them to the editor are not displayed. If I for example I make a new variable t = "test"; and then editor.setValue(t); then it works.

4

1 に答える 1

1

Yourdataは、コールバック関数の外では使用できません。コールバック内でエディターの値を設定します。

function app() {
    jQuery.get('http://localhost:2748/foo.txt', function (data) {
        alert(data);
        editor.setValue(data);
    });
}
于 2012-07-18T18:32:53.927 に答える