我在为全局变量赋值并在函数内部使用它时遇到问题。这是我的代码:
var chartinfo = {"c0":"0", "c1":"0"}; // This is my global variable
$.getJSON("http://127.0.0.1:8080/chartinfo", function(json1){
chartinfo = json1; // I need to assign json1's value to chartinfo
});
$(function () {
$(document).ready(function() {
alert("external chartinfo " + chartinfo.c0.name); // I need to use chartinfo here