ajax - Jquery executes in weird order -
Please refer to this code. I hope this is:
- Execute the executable which saves two values (
latitude andlongitude )- Use these values here =
var center = new google.maps.LatLng (resplat, resplon);The problem is that the code does not execute in this sequence. It "jumps" on the initial ajax and goes for a second time when it comes back first. This makes me two worthless useless. Can the code explain the logic behind the order being executed?
function initialize () {$ .ajax ({type: "GET", url: 'http: // ip-api .com / json', datatype: "Jason", success: Work (resp) {resplat = resp.lat; resplon = resp.lon;}}); // Google has touched its interface to some extent - it asks the API to use that new UI google.maps.visualRefresh = true; Var center = new google.maps.LatLng (resplat, resplon); // These are the options which set the initial zoom level, where the map is centered to start at the world level, and to show the map map var map = {zoom: 15, center: center, map type Do: google.maps.MapTypeId.G_NORMAL_MAP};Move that code to
reslat andStart the insidefunction of AJAX success callback () {$ .ajax ({type: "GET", url: 'http: // Ip -api.com/json ', datatype: "Jason", success: function {var resplat = resp.lat; var resplon = resp.lon; // Google has touched its interface to some extent - This tells that the new UI google.maps.visualRefresh = true; var center = new google.maps.LatLng (resplat, resplon); // These are the options that set the initial zoom level, where the map starts globally Second is concentrated, and the type of map to show Var map == {zoom: 15, center: Center, type map: google.maps.MapTypeId.G_NORMAL_MAP};}}); }$ Ajax is an async call as long as the data does not come (success handler) you have to do wait then you can use it.Another way to add
.done (foo) handler:$. Ajax ({.. ..}). Done (function (...) {/ * doing something});
- Use these values here =
Comments
Post a Comment