Как удалить определенные слова в URL-адресе при загрузке страницы с помощью JavaScript или jQuery

Я работаю с Esri Map. Когда я попытался загрузить данные json на карту, я обнаружил, что Word findAddressCandidates добавляется к URL-адресу при просмотре из консоли. Поэтому вместо http://localhost/data.json я использую http://localhost/data.json/findAddressCandidates.

Как удалить findAddressCandidates из URL-адреса, чтобы иметь http://localhost/data.json?

Некоторые инженеры Stack Overflow предлагают использовать History API согласно этот источник.

<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
  <title>ArcGIS API for JavaScript Tutorials: Find places</title>
  <style>
  html, body, #viewDiv {
  padding: 0;
  margin: 0;
  height: 100%;
  width: 100%;
  }
  </style>
  <link rel="stylesheet" href="https://js.arcgis.com/4.20/esri/themes/light/main.css">
  <script src="https://js.arcgis.com/4.20/"></script>

  <script>

  require([
    "esri/config",
    "esri/Map",
    "esri/views/MapView",
    "esri/tasks/Locator",
    "esri/Graphic"
    ], function(esriConfig,Map, MapView, Locator, Graphic) {


    esriConfig.apiKey = "my api key";

    const map = new Map({
      basemap: "arcgis-navigation"
    });

    const view = new MapView({
      container: "viewDiv",
      map: map,
      center: [18.9553, 69.6492], //Longitude, latitude
      zoom: 13
    });


    const places = ["Choose a place type...", "Parks and Outdoors", "Coffee shop", "Gas station", "Food", "Hotel"];

    const select = document.createElement("select","");
      select.setAttribute("class", "esri-widget esri-select");
      select.setAttribute("style", "width: 175px; font-family: 'Avenir Next W00'; font-size: 1em");

    places.forEach(function(p){
      const option = document.createElement("option");
      option.value = p;
      option.innerHTML = p;
      select.appendChild(option);
    });

    view.ui.add(select, "top-right");


   const locator = new Locator({
        url: "http://localhost/data.json"
    });


   // Find places and add them to the map
   function findPlaces(pt) {
    locator.addressToLocations({
      location: pt,
      maxLocations: 25,
      outFields: ["Place_addr", "PlaceName"]
    })

    .then(function(results) {
      view.popup.close();
      view.graphics.removeAll();

      results.forEach(function(result){
        view.graphics.add(
          new Graphic({
            attributes: result.attributes,  // Data attributes returned
            geometry: result.location, // Point returned
            symbol: {
             type: "simple-marker",
             color: "#000000",
             size: "12px",
             outline: {
               color: "#ffffff",
               width: "2px"
             }
            },

            popupTemplate: {
              title: "{PlaceName}", // Data attribute names
              content: "{Place_addr}"
            }
         }));
      });

    });

  }

  // Search for places in center of map
  view.watch("stationary", function(val) {
    if (val) {
       findPlaces(select.value, view.center);
    }
    });
  // Listen for category changes and find places
  select.addEventListener('change', function (event) {
    findPlaces(event.target.value, view.center);
  });


});
  </script>

  </head>
  <body>
    <div id="viewDiv"></div>
  </body>
</html>

person Nancy Moore    schedule 17.07.2021    source источник
comment
Попробуйте это url.parse(yoururl).pathname.split("/");.   -  person ksa    schedule 17.07.2021
comment
Обратите внимание, что здесь мы предпочитаем технический стиль письма. Мы мягко препятствуем приветствию, надежде на помощь, благодарности, предварительной благодарности, благодарственным письмам, пожеланиям, добрым пожеланиям, подписям, пожалуйста, не могли бы вы помочь, болтовне и сокращенным txtspk, мольбам, как долго вы застряли, советы по голосованию, мета-комментарии и т. д. Просто объясните свою проблему и покажите, что вы пробовали, чего ожидали и что на самом деле произошло.   -  person halfer    schedule 22.07.2021