Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3359254
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:51:00+00:00 2026-05-18T02:51:00+00:00

am making an ajax call to retrive json data i then store the retrived

  • 0

am making an ajax call to retrive json data

i then store the retrived data into associative arrays

but when i try to get the data from the associative arrays the keys and values in them are undefined
I am guessing its because the the data is getting stored as value[i], and as the loop is finished it no longer knows what i is, how do i go about fixing this?

can be seen on this page http://www.focus-on-plants.com/locator_iconed.php
here is my script

myUrl = 'geo_locator_icons.php';// url of php page that retrives the locations
    // start a new ajax call
    $.ajax({  
        type: "GET", //The type of HTTP verb (post, get, etc)  
        url: myUrl, //The URL from the form element where the AJAX request will be sent  
        dataType: 'json',
        success: function(dat) { //Triggered after a successful response from server    
            var myData = dat.icons;
            var count = myData.length - 1;
            console.log(dat)
            console.log(myData)

            for(i=0; i < count; i++){
                // Creating the icon 
                var icon_image = "'"+myData.folder_ico+myData.image_ico+"'" //set image
                var icon_size = "new google.maps.Size"+myData.iconsize_ico //set size
                var icon_origin = "new google.maps.Point(0, 0)" // The origin
                var icon_anchor = "new google.maps.Point"+myData.iconanchor_ico //set anchorpoint
                // Creating the shadow
                var shadow_image = "'"+myData.folder_ico+myData.shadow_ico+"'" //set image
                var shadow_size = "new google.maps.Size"+myData.shadowsize_ico //set size
                var shadow_origin = null // The origin
                var shadow_anchor = "new google.maps.Point"+myData.iconanchor_ico //set anchorpoint
                // Creating the shape
                var shape_type = 'poly'
                var shape_coord = myData.imagemap_ico
                // Creating the icon
                var icon = new google.maps.MarkerImage(icon_image);
                // Creating the shadow
                var shadow = new google.maps.MarkerImage(
                    shadow_image,
                    shadow_size,
                    shadow_origin,
                    shadow_anchor
                );
                // Creating a shape
                var shape = '{type: '+shape_type+', coord:'+shape_coord+'}'

                // add the icon to the mapIconsArray
                iconImageArray[myData.name_ico] = new google.maps.MarkerImage(
                    icon_image,
                    icon_size,
                    icon_origin,
                    icon_anchor
                );
                // add the icon to the shadowIconsArray
                iconShadowArray[myData.name_ico] = new google.maps.MarkerImage(
                    shadow_image,
                    shadow_size,
                    shadow_origin,
                    shadow_anchor
                );
                // add the shape to the shapeIconsArray
                iconShapeArray[myData.name_ico] = shape
            };
        },
        error: function(dat) { //Triggered if an error communicating with server   
            $("#geo_detail").append('<label>There was an error retriving the Icons: '+dat+'<label><br>');
            $('#loc_button').fadeIn('slow');
            return 0;
        },  
    });
    console.log(iconImageArray)
    console.log(iconShadowArray)
    console.log(iconShapeArray)

<———————–update on what i am trying to achive——————–>

The createIcons() function will run when the page loads after the map initialises.

I want it to store the data into the 3 arrays(now objects) i have created

var iconImageArray = {};
var iconShadowArray = {};
var iconShapeArray = {};

i have a function called addMarkers() which adds markers to the map i want to be able to change the marker image depending on the type of marker that is added.

the add marker script:

// ADD MARKER FUNCTION
// Adds a marker to the map
// PARAMS: 
// @myLatrLng - latLng object
// @dat - Data containg location Info
function addMarker(map, myData){
    // Create the marker
    // create the marker info first
    myLatLng = new google.maps.LatLng(myData.lat_mdt, myData.lng_mdt);
    markersArray.push(myLatLng);
    markersInfoArray.push(myData);
    var marker = new google.maps.Marker({
        position: myLatLng,
        map: map,
    title: myData.name_mdt,
    icon: iconImageArray[myData.name_etp],
    shadow: iconShadowArray[myData.name_etp],
    shape: iconShapeArray[myData.name_etp],
   });

   // Wrapping the event listener inside an anonymous function
   // that we immediately invoke and passes the variable i to.
   (function(myData, marker) {
       // Creating the event listener. It now has access to the values of
       // myData and marker as they were during its creation
       google.maps.event.addListener(marker, 'click', function() {
       //create thecontent for the infowindow
       var content = createContent(myData);
       var infowindow = new google.maps.InfoWindow({
           content: content
       });
       infowindow.open(map, marker);
    });
})(myData, marker);             
};

<———————-update———————————–>

well this is where i am at,
ive done loads of testing with static data and the icons for the map generate fine, so my actual google map code is ok and working.

As soon as i start trying to reference items from the myIconsArray object it all breaks and i get no console messages that are set up in the addMarkers function.

I do notice however when i look in the console for the myIcons Array thwe structure looks incorrect:

within myIconsArray i have 3 objects, icon{} shadow{}, shape{}

shape seems to be ok its ;like this:
shape{
orchid day{
coord{}
type{}
}
stokist{
coord{}
type{}

} 
website visitor{
    coord{} 
    type{}

}

}

but image and shadow objects have wrong names are like this:

image{
orchid day{
Na{} //should be size (value is correct)
anchor{} //shoule be anchorpoint (value is correct)
b{} should be origin (value is correct)
hb{} // should be image (value is correct)
hc{} do not kn ow why this is here is undefined and not used by me!!!
}
stokist{
coord{}
type{}

} 
website visitor{
    coord{} 
    type{}

}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T02:51:01+00:00Added an answer on May 18, 2026 at 2:51 am

    The last 3 console.log() show undefined because they run before the response is received from the request.

    Any code that relies on the AJAX response needs to be placed in (or called from) the success: callback.

    So try moving them to the end of your success: callback:

     success: function(dat) { 
           ...
            // add the icon to the shadowIconsArray
            iconShadowArray[myData.name_ico] = new google.maps.MarkerImage(
                shadow_image,
                shadow_size,
                shadow_origin,
                shadow_anchor
            );
            // add the shape to the shapeIconsArray
            iconShapeArray[myData.name_ico] = shape
        };
        console.log(iconImageArray)
        console.log(iconShadowArray)
        console.log(iconShapeArray)
     }, 
     error: func...
    

    EDIT: Additional issue was that the i variable was not being utilized to get the value of the item at the current iteration in the Array, as in myData[ i ].name_ico

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making an ajax call $.ajax({ url: urpath, type: 'POST', dataType: 'json', data:
So I have my JavaScript making an Ajax call to /my_controller/ajax_action but then in
I am making this ajax call: $.ajax({ url: /test/whatever, type: 'post', contentType: 'application/json' data:
When making an ajax call, when contentType is set to application/json instead of the
I am making an ajax call in jquery $.get(validate_isbn.php, {isbn: obj[16]}, function(answer) { console.log(answer);
I'm making an ajax call to an API that returns binary data. I'm wondering
Going slightly crazy here. I'm making an Ajax call using jQuery.post as follows: $.post('php/print.php',{data:dS},function(res){...
I'm making an AJAX call which returns XML data, and this is my 'success:'
I am making an ajax call to the server and then updating some stats.
I am making an AJAX call and I get the following: {status:Results Found,errorcode:0,result:[{name:test,id:1},{name:some,id:2}]} What

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.