tags:

views:

31

answers:

1

Hi guys, What's the best way to get a json response into an array that I can use in the below example? This is my function that calls triggers the ajax call:

function getMaps(){

    mapID = "aus";
    mapImg = 'map_australia.jpg';

    $.ajax({
        type: "GET",
        url: "getMap.asp",
        data: "id=" + mapID,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(response) { 

          //not sure what to do here        
        }

      });
      return //not sure what to return here 
      // it should resemble: return {id: 'aus', image: '/resources/images/maps/map_australia.jpg', data: '', maps: []};

};  

For testing purposes getMap.asp sends back the follwoing:

{'j':[{'id':'aus','image':'/images/maps/map_detail.jpg','data':'','maps':[]}]}
+1  A: 
return JSON.parse(response);

If you're asking about how to handle the asynchronous response, you need to restructure the code calling getMaps, as it can't directly return the response. Instead you should accept a callback as an argument.

Forrest