在jquery中创建一个变量global

时间:2014-09-01 08:14:20

标签: javascript jquery

第一个警报给我结果I,但第二个警报没有。我想让json_text全球化,我该怎么做?

window.json_text = "i want this global!";
$.getJSON('http://localhost:8000/views/points_retriever/', function(data) {
    //data is the JSON string
    json_text = "[";
    for (i = 0; i < data.length; i++) { 
        json_text += '{ x: "' + data[i][0]/100 + '", y: "' + data[i][1]/100 + '", note: "' + data[i][2] + '"},';
    }
    json_text = json_text.substring(0, json_text.length-1);
    json_text += "]";
    alert(json_text);
});
alert(json_text); 

0 个答案:

没有答案