4

If you all could help me out, I'd really appreciate it.

This is the error I am getting:

"Resource interpreted as Script but transferred with MIME type application/json." ("Resource" is referring to is the json response from google's servers.)

Here is my code:

  $(document).ready(function(){
    $.getJSON("http://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false&callback=?", function(jsondata) {
    });
  });
S L
  • 14,262
  • 17
  • 77
  • 116
Andrew
  • 3,901
  • 15
  • 50
  • 64
  • when i run that code i get "please use a post request" as the json response... perhaps try the $.ajax instead, specifying post? – nathan gonzalez Mar 12 '11 at 07:35

5 Answers5

5

Try this instead:

<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>

<script>
    $(document).ready(function(){
        var loc = "1600 Amphitheatre Parkway, Mountain View, CA";
        var geocoder = new google.maps.Geocoder();
        geocoder.geocode( {'address': loc },
            function(data, status) { console.log(data); });
    });
</script>
Pandincus
  • 9,506
  • 9
  • 43
  • 61
  • You are possibly the most awesome person ever. Thank you so much! – Andrew Mar 12 '11 at 07:50
  • Agreed, I've been looking for this exact solution. You are THE BOSS. – Tyler Brock Nov 02 '11 at 17:03
  • Out of curiosity... does anyone understand how google's apis for geocoding work (which one to use when), it seems like there are a couple different options, each of them working differently and with different restrictions and capabilities. Very confusing to say the least. – Tyler Brock Nov 04 '11 at 21:43
1

The site you are calling does not support JSONP, only returns as JSON.

Shaz
  • 15,637
  • 3
  • 41
  • 59
  • Thanks you very much for the response, but do you know how I could make my code work, now that I know the site I am calling only responds in json? – Andrew Mar 12 '11 at 07:38
  • @Andrew - my answer to your previous question (http://stackoverflow.com/questions/5281039/jquery-wont-get-json/5281137#5281137) showed how you could use the api objects to use geocoding. I can repost it here if you want... – Pandincus Mar 12 '11 at 07:39
  • Be aware that use of the geocoding only allows you to use the data in accordance with a Google Map. Take a look at the Terms Of Use – Shaz Mar 12 '11 at 07:42
1

In order to get JSON from another domain (such as googleapis.com), you must use JSONP rather than plain JSON (for more info, read up on same origin policy).

Fortunately, adding a GET parameter whose value is a question mark (callback=?, in your code) causes jQuery to attempt to make a JSONP call. Unfortunately, the site is ignoring your request for JSONP and serving straight JSON.

The two possible causes are that the site doesn't support JSONP (which would be odd for a public Google API) or that it expects the name to be something else (i.e. not callback=). Check out the Google API docs to see what the they expect / support.

Ben Blank
  • 54,908
  • 28
  • 127
  • 156
  • supported options: callback, base_domain, language, other_params --- apparently google does accept callback; thanks for eliminating one possible source of error, though – Andrew Mar 12 '11 at 07:41
0

So my Maps API is a bit rusty, but doesn't the callback=? at the end turn the output into a JSONP result, which is indeed a script?

Try ditching the callback part of the query string.

Charles
  • 50,943
  • 13
  • 104
  • 142
  • If I do that, then I end up with an Access-Control-Allow-Origin error. :( That is actually what I just fixed. – Andrew Mar 12 '11 at 07:39
0

Please tell me if this answers your question: webkit based browser interpretate the json as a script

Community
  • 1
  • 1
Phil C
  • 3,687
  • 4
  • 29
  • 51