PHP and Javascript value passing

I’m using Html5 geolocation to get the coordinates of the user and sending them via Javascript to an external PHP file to reverse geo-locate the adress:

xhr.open( 'GET', 'utility/fetch.php?lat='+lat+'&lng='+lng, true );

On fetch.php I’m reversing geo-locating the street adress and whatever I need parsing the response and sending it back.

function geo_callback(r){
    var result = //parsing r and getting required data
    /*
     some code here for declaring variables and stuff
    */
    //printing the result from database 
    xmlhttp.onreadystatechange=function() {
            if (xmlhttp.readyState==4 && xmlhttp.status==200) {
                document.getElementById("result").innerHTML=xmlhttp.responseText;
            }
    }
    //sending result to another external php to fetch data from database
    xmlhttp.open("GET", "utility/coord_to_add.php?result="+result ,true);
    xmlhttp.send(); 
}

Now my question is, is this an efficient way to do this? Let’s ignore all the error handling I am just providing the method I’m using here. Plus, I realized that the data I get back as result and print it inside the “result” div does not apply the CSS.


Source: html5

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.