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
1 Answer
Reset to default 3In 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
版权声明:本文标题:How to get JSON object data from a webpage using javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745006938a2637319.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论