0

I have a URL which returns JSON data. I would then like to use some parts of this data in Javascript. At the moment I'm getting an 'Uncaught Syntax Error' in the console when I run it.

My code looks like this:

var myAPIcall = "https://maps.googleapis.com/maps/api/geocode/json?address=SW1A1AA&callback=?";


$.get(myAPIcall, function( data ) {
    console.log("Place ID = " + data.results.place_id);
}, "json" );

It's the JSON itself which is causing the error.

How can I get the JSON (specifically the place_id, but I'd be happy with any of it) to display with the console.log? If I understand that much I should then be able to move on and use the place_id in my code.

Thanks

1
  • try data.results[0].place_id since results is an array Commented Aug 9, 2016 at 14:07

1 Answer 1

1

Check our query. Removing callback=? will result in a valid JSON :-)

var myAPIcall = "https://maps.googleapis.com/maps/api/geocode/json?address=SW1A1AA";


    $.getJSON(myAPIcall, function( data ) {
        console.log(data.results[0].place_id);
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.