Last active
April 25, 2016 17:46
-
-
Save AkarshSatija/724333886a40c13e3d58 to your computer and use it in GitHub Desktop.
Problem with asyncronous calls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
//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!');
});