Javascript 如何使用ajax调用在varibe中存储json数据

Javascript 如何使用ajax调用在varibe中存储json数据,javascript,json,ajax,google-maps,asp.net-ajax,Javascript,Json,Ajax,Google Maps,Asp.net Ajax,我希望使用ajax调用将JSON数据存储在变量中。如何编写ajax调用并将JSON数据值保存在变量中,以便在GoogleMaps中显示数据。需要JSON中的DustValue,并且应该在Google Maps js的变量中赋值 <head> <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCLi6lY_WbRa9mkWKc" type="text/javascript"></scr

我希望使用ajax调用将JSON数据存储在变量中。如何编写ajax调用并将JSON数据值保存在变量中,以便在GoogleMaps中显示数据。需要JSON中的
DustValue
,并且应该在Google Maps js的变量中赋值

<head>
    <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCLi6lY_WbRa9mkWKc" type="text/javascript"></script>
    <script>
        var myCenter = new google.maps.LatLng(22.8046, 86.2029);
        function initialize()
        {
            var mapProp = {
                center:myCenter,
                zoom:17,
                mapTypeId:google.maps.MapTypeId.ROADMAP
            };

            var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
            var DustValue=23;//  ajax call.. $.ajax({url: 'http://xyz.in/dust/get'......
            var dustbinstatus='';

            if(DustValue<50){
                dustbinstatus = 'img/dustbinempty.png';
            } else if(DustValue>50 && DustValue<90){
                dustbinstatus = 'img/dustbinfull.png';
            } else if(DustValue>90){
                dustbinstatus = '3.jpg';
            }

            var marker=new google.maps.Marker({
                position:myCenter,
                icon: v_icon
            });

            marker.setMap(map);
        }

        google.maps.event.addDomListener(window, 'load', initialize);
    </script>
</head>

<body>
    <div id="googleMap" style="width:1580px;height:780px;"></div>
</body>

您需要使用
success
回调处理程序将响应存储在变量中,下面是一个示例

    var dustValue;    
    $.ajax({
          type: "GET",
          url: "your_url_goes_here",
          dataType: "json",
          success : function(data) {
              dustValue = data;
           }
        });
希望这有帮助

    var dustValue;    
    $.ajax({
          type: "GET",
          url: "your_url_goes_here",
          dataType: "json",
          success : function(data) {
              dustValue = data;
           }
        });