admin管理员组文章数量:1394094
I'd like to load a JSON feed from an external source using Javascript; what's the best method? I've been working a lot in PHP where it would be easy to do so with file_get_contents or cURL. Is there a related function or process in Javascript?
I'd like to load a JSON feed from an external source using Javascript; what's the best method? I've been working a lot in PHP where it would be easy to do so with file_get_contents or cURL. Is there a related function or process in Javascript?
Share Improve this question edited May 26, 2009 at 22:27 Daniel Bachhuber asked May 26, 2009 at 21:50 Daniel BachhuberDaniel Bachhuber 7132 gold badges10 silver badges20 bronze badges2 Answers
Reset to default 5jQuery to get some JSON data might look like this:
$.getJSON("http://pathtodata.js", function(json){
alert(json.dot.notation);
});
A source is specified along with a callback function. Read up on jQuery JSON documentation: http://api.jquery./jQuery.getJSON/
Javascript XMLHTTPRequest has same-domain origin policy so you will be restricted to only loading data from URLs from the same domain that your script was loaded from. JSONP is one way to get around this. Another way is to use a proxy script on your domain, which in turns performs its own HTTP calls for you. For more information on JSONP check out this article:
http://www.ibm./developerworks/library/wa-aj-jsonp1/
本文标签: jqueryImporting a JSON feed from an external source in JavascriptStack Overflow
版权声明:本文标题:jquery - Importing a JSON feed from an external source in Javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744569571a2613254.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论