Ответы пользователя по тегу JavaScript
  • Как пофиксить ошибку PWA?

    @pavel__sidorov Автор вопроса
    ошибка изменилась
    Uncaught (in promise) TypeError: Failed to execute 'fetch' on 'WorkerGlobalScope': Cannot construct a Request with a Request object that has already been used

    self.addEventListener('install', function(event) {
      var indexPage = new Request('index.php');
      event.waitUntil(
        fetch(indexPage).then(function(response) {
          return caches.open('pwabuilder-offline').then(function(cache) {
            console.log('[PWA Builder] Cached index page during Install'+ response.url);
            return cache.put(indexPage, response);
          });
      }));
    });
    self.addEventListener('fetch', function(event) {
      var updateCache = function(request){
        return caches.open('pwabuilder-offline').then(function (cache) {
          return fetch(request).then(function (response) {
            console.log('[PWA Builder] add page to offline'+response.url)
            return cache.put(request, response);
          });
        });
      };
      event.waitUntil(updateCache(event.request));
      event.respondWith(
        fetch(event.request).catch(function(error) {
          console.log( '[PWA Builder] Network request Failed. Serving content from cache: ' + error );
          return caches.open('pwabuilder-offline').then(function (cache) {
            return cache.match(event.request).then(function (matching) {
              var report =  !matching || matching.status == 404?Promise.reject('no-match'): matching;
              return report
            });
          });
        })
      );
    })
    Ответ написан
    Комментировать
  • Как привязать кнопку определения местоположения к своему html элементу (api яндекс карты)?

    @pavel__sidorov Автор вопроса
    <div class="map_btn" id="geo">Определить местоположение</div>

    var a = document.getElementById('geo');
    
    a.onclick = function() {
    		geolocation.get({
    		mapStateAutoApply: true
    		})
    		.then(
    		function(result) {
    		// Получение местоположения пользователя.
    		var userAddress = result.geoObjects.get(0).properties.get('text');
    		var userCoodinates = result.geoObjects.get(0).geometry.getCoordinates();
    		result.geoObjects.get(0).properties.set({
    		balloonContentBody: 'Адрес: ' + userAddress +
    		'<br/>Координаты:' + userCoodinates
    		});
    		myMap.geoObjects.add(result.geoObjects)
    		},
    		function(err) {
    		console.log('Ошибка: ' + err)
    		}
    		);
        }
    Ответ написан
    Комментировать