1

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
  • You're not looking to return an array, but an object. Commented Sep 3, 2010 at 0:30

1 Answer 1

1
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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.