{"programmers":[{"firstName":"Brett","lastName":"McLaughlin","email":"aaaa"},
{"firstName":"Jason","lastName":"Hunter","email":"bbbb"},
{"firstName":"Elliotte","lastName":"Harold","email":"cccc"}
],
"authors":[
{"firstName":"Isaac","lastName":"Asimov","genre":"sciencefiction"},
{"firstName":"Tad","lastName":"Williams","genre":"fantasy"},
{"firstName":"Frank","lastName":"Peretti","genre":"christianfiction"}
],
"musicians":[
{"firstName":"Eric","lastName":"Clapton","instrument":"guitar"},
{"firstName":"Sergei","lastName":"Rachmaninoff","instrument":"piano"}
]}
var people={"programmers":[{"firstName":"Brett","lastName":"McLaughlin","email":"aaaa"},
{"firstName":"Jason","lastName":"Hunter","email":"bbbb"},
{"firstName":"Elliotte","lastName":"Harold","email":"cccc"}
],
"authors":[
{"firstName":"Isaac","lastName":"Asimov","genre":"sciencefiction"},
{"firstName":"Tad","lastName":"Williams","genre":"fantasy"},
{"firstName":"Frank","lastName":"Peretti","genre":"christianfiction"}
],
"musicians":[
{"firstName":"Eric","lastName":"Clapton","instrument":"guitar"},
{"firstName":"Sergei","lastName":"Rachmaninoff","instrument":"piano"}
]}
这样就不需要考虑跨域问题,直接在dom里引用,然后在js中获取。
对于只有静态的网页帮助很大
1
mcfog 2015-01-21 20:53:01 +08:00 via Android 1
为什么不jsonp?
|
3
takatost 2015-01-21 21:12:38 +08:00
jsonp
|
4
luoweihua7sync 2015-01-21 21:14:59 +08:00
var str="{a:1,b:2}";
var json=(new Function("return "+str))(); console.log(json); 要么就用JSONP |
5
14ly OP jsonp需要服务器支持,不能达到我的要求,但是找到了“jsonp代理”,可用。
附上我修改后的雅虎代理使用: src = 'http://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=zh-CN' $.getJSON("http://query.yahooapis.com/v1/public/yql", { q: 'select * from json where url="' + src + '"', format: "json" }, function(data) { console.log(data.query.results.json.images) }) |