admin管理员组

文章数量:1406306

I am new to web and I need to get JSON object for a webpage that has data displayed this:

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

I tried use jquery's $.getJSON to get the object but it didn't work.

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

I am wondering how to get this information correctly?

I am new to web and I need to get JSON object for a webpage that has data displayed this:

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

I tried use jquery's $.getJSON to get the object but it didn't work.

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

I am wondering how to get this information correctly?

Share Improve this question edited Sep 23, 2011 at 17:32 user959974 asked Sep 23, 2011 at 17:13 user959974user959974 3792 gold badges9 silver badges25 bronze badges 1
  • 2 There is no such thing as a JSON object. Also, if you use document.write() there, you will replace the current contents of the page. – Matt Ball Commented Sep 23, 2011 at 17:16
Add a ment  | 

1 Answer 1

Reset to default 3

In order for this to work, you need to define jsonp, jsonp allows you to gain read access to another site's document, as the alternate version is barred.

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

本文标签: How to get JSON object data from a webpage using javascriptStack Overflow