Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

145
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!