Home > Blockchain >  what is the solution to this problem "failed to load resource: net::ERR_CONNECTION_REFUSED http
what is the solution to this problem "failed to load resource: net::ERR_CONNECTION_REFUSED http

Time:07-19

I have a problem with my program. this is a program about geographic information system that uses the LeatlefJs library, I also use the letlef routing machine feature. the problem is the system can't display the route it should be able to display, I don't really understand. this is the script.

        function getDirectRoute(index, callbackFunction){
            var dari = marker_awal.getLatLng().lat   ","   marker_awal.getLatLng().lng;
            var tujuan = markerCabang[index].getLatLng().lat   ","   markerCabang[index].getLatLng().lng;
            $.ajax({
                  type: "GET",
                  url: "http://localhost:8989/route?point="   dari   "&point="   tujuan   "&points_encoded=false&instructions=false&vehicle=motorcycle&ch.disable=true&weighting=shortest&algorithm=alternative_route",
                  dataType: 'json',
                  contentType: "application/json",
                  success: function (data) {
                    successReveived  ;
                    var coordinates = data.paths[0].points.coordinates;
                    tempDistance = 0;      
                    for(var j=0; j<coordinates.length; j  ){
                        if(j==0){
                            tempDistance  = euclidean(marker_awal.getLatLng().lat, marker_awal.getLatLng().lng, coordinates[j][1], coordinates[j][0]);
                        } else {
                            tempDistance  = euclidean(coordinates[j-1][1], coordinates[j-1][0], coordinates[j][1], coordinates[j][0]);
                        }
                    }
                    distanceGH[index] = data.paths[0].distance;
                    distanceManual[index] = tempDistance.toFixed(4);
                    
                    if(successReveived == markerCabang.length && typeof(callbackFunction == 'function')){
                        callbackFunction();
                    }
                  }
            });
        } 

the error is like this

failed to load resource: net::ERR_CONNECTION_REFUSED http://localhost:8989/route?point=3.611967691620835,98.67254734039308&point=3.611126,98.67548&points_encoded=false&instructions=false&vehicle=motorcycle&ch.disable=true&weighting=shortest&algorithm=alternative_route

CodePudding user response:

(I cannot comment yet, so trying to help you with an answer)

  1. Make sure you have a working valid backend to respond for the JS library (see https://www.liedman.net/leaflet-routing-machine/tutorials/alternative-routers/ for valid backends)
  2. Try entering the URL directly in your browser (without Leaflet or anything else): http://localhost:8989/route -> You should see JSON output, even if it says malformed or invalid request. If you are having the network issue here already you need to check the network layer (e.g. firewalls, port binding of the backend etc.), continue if thats not the case.
  3. Open the network tab in your browsers DEV tools (F12) and filter all connections to your backend. Now try the map / leafletJS and check for additional information in that tab. You might see an error that your browser blocked the request due to something related to Cross-Origin-Requests (CORS).
  • Related