I have this script that calls a .net WebService
msg = $.toJSON(
$.ajax({
type: "POST",
url: "http://[url]/ETS.UI/WebServices/LocationService.asmx/GetMappingLocationDetails",
contentType: "application/json; charset=utf-8",
data: $.toJSON({'componentId':994}),
dataType: "json",
async: false
}).responseText
);
And I recieve the following value in the msg variable:
""{\"d\":\"{\\\"ComponentId\\\":994,\\\"Latitude\\\":32.219627009236405,\\\"Longitude\\\":-110.96843719482422,\\\"LocationName\\\":\\\"Tucson\\\",\\\"StreetAddress\\\":\\\"7201 E 22nd Street \\\",\\\"City\\\":\\\"Tucson\\\",\\\"State\\\":\\\"AZ\\\",\\\"PostalCode\\\":null}\"}""
I have no idea why this would format this way, seems to only do this in responseText.
Does anyone have any ideas?
As SLaks mentioned, synchronous AJAX is a Very Bad Idea®. If you’re looping over items to plot on a map, you don’t want to make a server call for every item anyway – you’ll get absolutely horrid performance with more than just a couple items due to the cumulative latency of all the round-trips.
A much better method would be to submit an array of
componentIds to your server. The server can then loop over the array of IDs and return an array of lat/longs and whatever else for you to plot on the map.You might also want to check out this plugin which makes calling ASMX services from jQuery a little easier.