Redirection inside API Request not working in iPhone

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • oandrekerr
    New Member
    • Feb 2020
    • 1

    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.

    Code:
    function calc(){
    $('#btCalc').addClass('is-loading');
    var req = new XMLHttpRequest();
    req.open('GET','https://maps.googleapis.com/maps/api/geocode/json?address='+$('#cdd').val()+'&key=PRIVATE_KEY',false);
    req.onload = function(){
        console.log('carregou!');
    var data = JSON.parse(req.responseText);
    lat = data.results[0].geometry.location.lat;
    lng = data.results[0].geometry.location.lng;
    cdN = data.results[0].formatted_address
    console.log("Cidade natal: "+cdN+" (Lat "+lat+" Long "+lng+")");
    
    
    uf = data.results[0].address_components[2].short_name;
    
    if(uf=="BR"){
        uf = data.results[0].address_components[1].short_name;
    } 
    
    getGMT(lat, lng);
    
    }
    
    req.send();
    return true;
    }
    
    function getGMT(lat, lng){
    var req = new XMLHttpRequest();
    var apiUrl = 'https://api.timezonedb.com/v2.1/get-time-zone?key=PRIVATE_KEY&format=json&by=position&lat='+lat+'&lng='+lng;
    req.open('GET',apiUrl,false);
    
    req.onload = function(){
    
    var data = JSON.parse(req.responseText);
    Utc = (data.gmtOffset/3600);
    redirectPage();
    return true;
    }
    
    req.send();
    return true;
    }
    
    function redirectPage(){
    try{
    if($('#Verao').prop('checked')){
        Utc = Utc+1;
    } 
    
    nome = $("#nome").val();
    dados = "dataNasc="+dataNasc()+"&lat="+lat+"&lng="+lng+"&utc="+Utc+"&cdn="+cdN+"&nome="+nome+"&ayanamsha=CUSTOM_AYANAMSHA";
    
    var urlFinal = 'chart.php?'+dados;
    alert(urlFinal);
    $('#redirectPage').attr('href',urlFinal);
    $('#btCalc').attr('href',urlFinal);
    $('#redirectPage')[0].click();
    $('#redirectPage').show();
    $('#btCalc').attr('onclick','');
    }catch(e){}
    
    }
    Last edited by Rabbit; Feb 19 '20, 10:26 PM. Reason: external link removed
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5388

    #2
    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?
    Last edited by gits; Feb 21 '20, 09:19 AM.

    Comment

    Working...