How to get JSON object data from a web page using javascript

I am new to the web and I need to get a JSON object for a webpage that displays data:

{ "expires": "2011-09-24T01:00:00", "currencies": { "BZD": { "a": "2.02200", "b": "1.94826" }, "YER": { "a": "220.050", "b": "212.950" } } 

I tried using jquery $ .getJSON to get the object, but it did not work.

<script> $.getJSON("http://m.somewebsite.com/data", { format: "json" }, function(data) { document.getElementById('test').innerHTML = data; }); </script>

I am wondering how to get this information correctly?

+4
source share
1 answer

For this to work, you need to define jsonp, jsonp allows you to read access to another site document, since the alternate version is not allowed.

 $.getJSON("http://m.somewebsite.com/data?callback=?", { format: "json" }, function(data) { document.write(data); }); 
+3
source

All Articles