Skip to content

Instantly share code, notes, and snippets.

@AkarshSatija
Last active April 25, 2016 17:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AkarshSatija/724333886a40c13e3d58 to your computer and use it in GitHub Desktop.
Save AkarshSatija/724333886a40c13e3d58 to your computer and use it in GitHub Desktop.
Problem with asyncronous calls
function tryIt() {
var sheets = {
"1": {
"name": "type1",
"marker": "http://www.google.com/mapfiles/markerA.png"
},
"2": {
"name": "type2",
"marker": "http://www.google.com/mapfiles/markerB.png"
},
"3": {
"name": "type3",
"marker": "http://www.google.com/mapfiles/markerC.png"
},
"4": {
"name": "type4",
"marker": "http://www.google.com/mapfiles/markerD.png"
},
"5": {
"name": "type5",
"marker": "http://www.google.com/mapfiles/markerE.png"
},
"6": {
"name": "type6",
"marker": "http://www.google.com/mapfiles/markerF.png"
},
"7": {
"name": "type7",
"marker": "http://www.google.com/mapfiles/markerG.png"
}
};
window.sheets=sheets;
var url = "http://localhost:3000/";
for (var key in sheets) {
console.log(sheets[key].marker)
$.ajax({
type: "GET",
url: url + "?key=" + key,
success: function(data) {
loadMarker(key, data);
},
error: function() {
console.log("Are you sure you are connected to the internet?");
}
});
}
function loadMarker(key, data) {
//URL: http://www.google.com/mapfiles/markerG.png?token=*SomeToken*
console.log("Final url:"+ sheets[key].marker+"?token="+data.token)
sheets[key].finalURL=sheets[key].marker+"?token="+data.token;
}
}
@AkarshSatija
Copy link
Author

AkarshSatija commented Apr 25, 2016

//related nodejs code:

var express = require('express');
var app = express();

app.get('/', function (req, res) {
res.header("Access-Control-Allow-Origin", "");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
res.json({"token":req.query*77});
});

app.listen(3000, function () {
console.log('Example app listening on port 3000!');
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment