473,396 Members | 2,085 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Redirection inside API Request not working in iPhone

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
1 1873
gits
5,390 Expert Mod 4TB
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

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

Similar topics

13
by: souissipro | last post by:
Hi, I have written a C program that does some of the functionalities mentionned in my previous topic posted some days ago. This shell should: 1- execute input commands from standard input,...
1
by: Mike Hofer | last post by:
I really need some help, and I'd appreciate any that you folks can provide. The ASP.NET application in question uses version 1.1 of the .NET Framework. All of the pages use a common base class...
7
by: injia | last post by:
I have my server request working but it will only make the request once. onclick calls the ajax function but only once. when i change entires in the form and hit the button nothing happens Here is...
0
by: babu8880 | last post by:
www.convensysglobal.com/elearn You can login and attend courses and similar resources ask your doubts from experienced engineers in iphone and Objective C Domain You can attend live classes...
0
by: phpuser123 | last post by:
I have a page client.php that submits a form and goes to server.php.. server.php adds some post requests and redirects the page to client.php.. Is it possible to use ajax here to access the post...
0
by: prad scott | last post by:
Php header("location:index.php") it is not redirecting in server in localhost its working fine. But after uploading to server header redirection is not working
1
by: mobileman | last post by:
Our technology packed iPhones act as our trusted sidekicks when we step out to face the world by giving us access to the world with a single tap. But when our iPhone confidant runs out of battery...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.