Does jQuery interpret json as a script?

If you could all help me, I would really appreciate it.

This is the error I get:

"The resource is interpreted as Script, but passed with a MIME application such as / json." (The "Resource" refers to a json response from google 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) { }); }); 
+4
source share
5 answers

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> 
+5
source

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

+1
source

To get JSON from another domain (e.g. googleapis.com), you should use JSONP and not plain JSON (for more information, check out the same origin policy ).

Fortunately, adding a GET parameter whose value is a question mark ( callback=? In your code) causes jQuery to try to make a JSONP call. Unfortunately, the site ignores your JSONP request and serves directly JSON.

Two possible reasons: the site does not support JSONP (which would be strange for the Google public API) or that it expects the name to be something else (i.e. not callback= ). Check out the Google API docs for what they expect / support.

+1
source

So my Maps API is a bit rusty but not callback=? at the end turns the output into a JSONP result, which really is a script?

Try to drop the query string callback part.

0
source

Please tell me the answer to this question: webkit-based browser interprets json as a script

0
source

Source: https://habr.com/ru/post/1343417/


All Articles