Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

146
Visualizações
MapQuest, PlaceSearch.js (in promise) error

I have a simple input field, in which when the user starts typing it will call the place-search.js script. When I start typing I get the following error:

Uncaught (in promise) Error: Uncaught, unspecified "error" event. ([object Response])

here is the function that listens for user input in the text field.

function addlistener(id){
        // This example will load jQuery dynamically, but this could be any script...
        loadScripts({
          test: function() { return typeof placeSearch !== 'undefined'; },
          scripts: 'https://api.mqcdn.com/sdk/place-search-js/v1.0.0/place-search.js',
          done: function() { 
           placeSearch({
                key: key,
                container: document.querySelector('#'+id),
                useDeviceLocation: useDeviceLocation,
                collection: collection
              });
          }
        }); 
    }

Can someone explain what this error means, or how to go about fixing it? Any guidance or help would be appreciated.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I was able to figure out the problem. So when you look at the function:

function addlistener(id){
        // This example will load jQuery dynamically, but this could be any script...
        loadScripts({
          test: function() { return typeof placeSearch !== 'undefined'; },
          scripts: 'https://api.mqcdn.com/sdk/place-search-js/v1.0.0/place-search.js',
          done: function() { 
           placeSearch({
                key: key,
                container: document.querySelector('#'+id),
                useDeviceLocation: useDeviceLocation,
                collection: collection
              });
          }
        }); 
    }

the useDeviceLocation variable holds the users current location. The app will prompt the user to allow us to get their location. If the user says "no", that variable will remain null. The function requires that variable to have a value thats not null.

So there are many ways to fix this:

Fix 1: Simply remove the useDeviceLocation: useDeviceLocation line.

Fix 2: We can write an if loop, which will check to see if useDeviceLocation is null. If it is, it will run case 1 code, or else it will run case 2 code. In our situation, there is only two cases, either we have a location, or don't.

function addlistener(id,useDeviceLocation){
if(useDeviceLocation){
  loadScripts({
      test: function() { return typeof placeSearch !== 'undefined'; },
      scripts: 'https://api.mqcdn.com/sdk/place-search-js/v1.0.0/place-search.js',
      done: function() { 
       placeSearch({
            key: key,
            container: document.querySelector('#'+id),
            useDeviceLocation: useDeviceLocation,
          });
      }
    }); 
}else{
  loadScripts({
    test: function() { return typeof placeSearch !== 'undefined'; },
    scripts: 'https://api.mqcdn.com/sdk/place-search-js/v1.0.0/place-search.js',
    done: function() { 
      placeSearch({
        key: key,
        container: document.querySelector('#'+id),
      });
    }
  });   
}
}

  
 
about 4 years ago · Juan Pablo Isaza Relatório

0

Is there someplace we can see this running now? Can you confirm the place-search.js file has successfully loaded before it is called?

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda