Note that there are some explanatory texts on larger screens.

plurals
  1. PORun a function from within a each loop (ajax.response)
    primarykey
    data
    text
    <p>I'm having problems trying to pass data to a function from within a each loop. I've roughly pasted my code below. Basically functionA gets JSON data, passes the response to functionB. I want to then pass each response item to functionC so they can be added to an array to plot markers using google maps. Any help would be appreciated. Thanks</p> <pre><code>if(app == undefined) var app = {}; app.Application = function() { this.functionA = function(){ var self = this; var urlHash = location.hash; accessToken = urlHash.split('=')[1]; if (!accessToken) { return false; } else { $.getJSON(instaAPIuri+"users/" + id + "/media/recent?access_token=" + accessToken + "&amp;callback=?", self.functionB); }; }; this.functionB = function(response){ var self = this; //Error codes if (response.meta.code == 400) { alert(response.meta.error_message); } //Create picture elements with basic information and image $.each(response.data, function (i, item) { //If item.location == null, while trying to get geolocation = error if (item.location != null) { functionC( item.location.latitude, item.location.longitude, item.images.thumbnail.url, item.user.username); } }); }; this.functionC = function(latitude, longitude, imgurl, user) { var self = this; var latLngPosition = new google.maps.LatLng(latitude, longitude); //Create marker with custom assets marker = new google.maps.Marker({ position:latLngPosition, icon: new google.maps.MarkerImage(imgurl, new google.maps.Size(110, 110), new google.maps.Point(0,0), new google.maps.Point(32, 32)), title: user, map:map }); //Push in array to delete later markersArray.push(marker); }; this.init(); }; $(function() { var app = new app.Application(); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload