Access to variable that is returned from the $.ajax "success" setting?
Hi,
I am trying to access a variable that is return from the "success" setting from an $.ajax call. I am not sure how to do this. I have attached the code below. Maybe there i a different way to get this variable?
- $( function( $ ){
- var xmlPath = '/site_media/xml/regions.xml';
- var regionMap;
-
- function parseXml( xml ){
- var map = {};
- $( xml )
- .find( 'region' )
- .each( function(){
-
- var regionName = $( this ).find( 'regionName' ).text();
- var manager = $( this ).find( 'manager' ).text();
- var phone = $( this ).find( 'phone' ).text();
- var email = $( this ).find( 'email' ).text();
-
- map[ regionName ] = {
-
- 'regionName' : regionName,
- 'manager' : manager,
- 'phone' : phone,
- 'email' : email
- };
-
-
- }
-
- );
- return map;
- }
- //get the xml
- options = {
- type: 'GET',
- url: xmlPath,
- dataType: 'xml',
- success: function(data){
- //NEED ACCESS TO THIS VARIABLE!!!
- regionMap = parseXml( data );
-
- },
- error: function(){
-
- alert( 'Could not load XML file for contact');
-
- }
- };
-
- $.ajax(options);
-
- // NO GO :(
- alert( regionMap.Central );
- });