We help IT Professionals succeed at work.

How can I verify that a jQuery getScript method has successfully loaded the script.

dlearman1
dlearman1 asked
on
311 Views
Last Modified: 2018-02-06
The script to be loaded is a Google Maps Directions Services API.  As I understand it, when this script executes it queries a Google server tyo verify a valid API key is included in the script, and if so executes the script's callback function. Because I am loading the Google map into a Bootstrap modal, I must constrain the script to only execute after the modal is open. To accomplish this I'm attempting to dynamically load the script into a function using the jQuery getScript method.
$('#googleMapLgModalArtessa').on('shown.bs.modal', function() {
     $.getScript("http://maps.googleapis.com/maps/api/js?key=My_API_Key&callback=initializeMap")
         .done(function() {
              console.log(API Key load was success);
          });
          .fail(function() {
               console.log("API Key failed to load");
    });
});

Open in new window


I'm getting nothing in the console log. So if the code looks valid, then there just isn't a connection with the Google server. The API key is valid and activated as far as I can tell according to the Google Developers Console.  Is there a way to test for a working Google maps API key? Is the getscript code correct?
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2004
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Top Expert 2010
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.