首页 > 解决方案 > Rest API不通过android触发JavaScript但在浏览器中工作

问题描述

        <?php 




    $conn = mysqli_connect('localhost','eyukti_home_roc','4nYntQuCjPYR','eyukti_home_roc');

    $user_id = $_GET['user_id'];


    $sql = mysqli_query($conn,"SELECT * FROM `vehicle_type` WHERE status = '1' AND is_delete !='1'"); 


    include("../firebase.php");       
    ?>

    <script>
    (function() {
      // Initialize the Firebase SDK
    firebase.initializeApp({
     databaseURL: "https://xxx-xxxx.firebaseio.com"
    });

    var  user_new_lat = null;
    var  user_new_lng = null;

    var ref_driver_location = firebase.database().ref('Driver/DriverLocation');

    var  ref_user = firebase.database().ref('User').child('<?php echo $user_id; ?>');
    var ref_nearest_driver = ref_user.child('NearestDriver');
    var ref_availableDriver = ref_user.child('availableDriver');
    var ref_driver = firebase.database().ref('Driver');
    var geoFire = new geofire.GeoFire(ref_driver_location);


    var user_new_location = ref_user.child('UserLocation/UserLocationNew');
    var user_old_location = ref_user.child('UserLocation/UserLocationOld');


    var user_location = ref_user.child('UserLocation');

         var user_new = ref_user.child('UserLocation/GeoLocation');

    var geoQuery = null;


    user_old_location.on("value", function(newuser_snapshot) {


    user_location.once("value", function(nearest_driver_snapshot) {

           user_new_lat = nearest_driver_snapshot.child("GeoLocation/location/l/0").val();
           user_new_lng = nearest_driver_snapshot.child("GeoLocation/location/l/1").val();  
         var user_old_lat = nearest_driver_snapshot.child("UserLocationOld/lat").val();
         var user_old_lng = nearest_driver_snapshot.child("UserLocationOld/lng").val();



                var geoFireUserLocation = new geofire.GeoFire(user_new);     
                var geoQueryUserLocation = geoFireUserLocation.query({
                    //alert('yes');
                  center: [parseFloat(user_old_lat),parseFloat(user_old_lng)],
                  radius: 0.6
                });


                     var onReadyRegistration = geoQueryUserLocation.on("ready", function() {
                  console.log("GeoQuery has loaded and fired all other events for initial data");
                });


                var onKeyEnteredRegistration = geoQueryUserLocation.on("key_entered", function(key, location, distance) {


                                 geoQuery = geoFire.query({
                                  center: [parseFloat(user_old_lat),parseFloat(user_old_lng)],
                                  radius: 3.0
                                });










    }, function (error) {
       console.log("Error: " + error.code);
    });



    }, function (error) {
       console.log("Error: " + error.code);
    });


    })();


    </script>

    <!--<script src="../firebase_js/insertuser.js" defer></script>-->

问题是这个firebase Geofire在我从浏览器点击这个api时工作,但当我在android中调用这个api时没有点击我试图在邮递员中调用API,但它从php给出响应但没有触发geofire函数并且还给出javascript代码作为响应. 我无法找到解决方案,因为我无法找到问题

标签: javascriptphpandroidfirebasegeofire

解决方案


如果您在android中使用webview,您需要为webview启用javascript,如下所示

WebView mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });
mWebView.loadUrl("htpps://yoururl");

推荐阅读