By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,264 Members | 1,743 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,264 IT Pros & Developers. It's quick & easy.

Redirection inside API Request not working in iPhone

P: 1
I have a script that get data from two different APIs, but it isn't redirecting in the end of the last request to to the generated link, but it happens only for iPhone users. What am I doning wrong? I can't see it anywhere.

Expand|Select|Wrap|Line Numbers
  1. function calc(){
  2. $('#btCalc').addClass('is-loading');
  3. var req = new XMLHttpRequest();
  4. req.open('GET','https://maps.googleapis.com/maps/api/geocode/json?address='+$('#cdd').val()+'&key=PRIVATE_KEY',false);
  5. req.onload = function(){
  6.     console.log('carregou!');
  7. var data = JSON.parse(req.responseText);
  8. lat = data.results[0].geometry.location.lat;
  9. lng = data.results[0].geometry.location.lng;
  10. cdN = data.results[0].formatted_address
  11. console.log("Cidade natal: "+cdN+" (Lat "+lat+" Long "+lng+")");
  12.  
  13.  
  14. uf = data.results[0].address_components[2].short_name;
  15.  
  16. if(uf=="BR"){
  17.     uf = data.results[0].address_components[1].short_name;
  18.  
  19. getGMT(lat, lng);
  20.  
  21. }
  22.  
  23. req.send();
  24. return true;
  25. }
  26.  
  27. function getGMT(lat, lng){
  28. var req = new XMLHttpRequest();
  29. var apiUrl = 'https://api.timezonedb.com/v2.1/get-time-zone?key=PRIVATE_KEY&format=json&by=position&lat='+lat+'&lng='+lng;
  30. req.open('GET',apiUrl,false);
  31.  
  32. req.onload = function(){
  33.  
  34. var data = JSON.parse(req.responseText);
  35. Utc = (data.gmtOffset/3600);
  36. redirectPage();
  37. return true;
  38. }
  39.  
  40. req.send();
  41. return true;
  42. }
  43.  
  44. function redirectPage(){
  45. try{
  46. if($('#Verao').prop('checked')){
  47.     Utc = Utc+1;
  48.  
  49. nome = $("#nome").val();
  50. dados = "dataNasc="+dataNasc()+"&lat="+lat+"&lng="+lng+"&utc="+Utc+"&cdn="+cdN+"&nome="+nome+"&ayanamsha=CUSTOM_AYANAMSHA";
  51.  
  52. var urlFinal = 'chart.php?'+dados;
  53. alert(urlFinal);
  54. $('#redirectPage').attr('href',urlFinal);
  55. $('#btCalc').attr('href',urlFinal);
  56. $('#redirectPage')[0].click();
  57. $('#redirectPage').show();
  58. $('#btCalc').attr('onclick','');
  59. }catch(e){}
  60.  
  61. }
  62.  
  63.  
Feb 19 '20 #1
Share this Question
Share on Google+
1 Reply


gits
Expert Mod 5K+
P: 5,387
can you tell a bit more detailed what exactly happens there? You setting 2 hrefs to your new url - then try to fire a click event the #redirectPage-node and 'remove' a click event from the #btCalc-node. What exactly are these nodes? I suspect that the click()-method call is not working correctly - but why not setting the location of the desired viewport directly?
Feb 19 '20 #2

Post your reply

Sign in to post your reply or Sign up for a free account.