admin管理员组文章数量:1419666
I'm trying to download some data using pure javascript/html from cross-domain, dropbox to be specific.
<html>
<head>
</head>
<body>
<div id = 'twitterFeed'></div>
<script>
function myCallback(dataWeGotViaJsonp){
var text = '';
var len = dataWeGotViaJsonp.length;
for(var i=0;i<len;i++){
twitterEntry = dataWeGotViaJsonp[i];
text += '<p><img src = "' + twitterEntry.user.profile_image_url_https +'"/>' + twitterEntry['text'] + '</p>'
}
document.getElementById('twitterFeed').innerHTML = text;
}
</script>
<script type="text/javascript" src=".json?count=10&callback=myCallback"></script>
</body>
for some reason, the json is not loading. however the json loads correctly when I make the url ".json?count=10&callback=myCallback" instead. I got this example from here
Can anybody explain why dropbox doesn't work?
thanks!
UPDATE:
<script type=text/javascript>
function myCallback(dataWeGotViaJsonp){
alert(dataWeGotViaJsonp);
}
</script>
<script type="text/javascript" src="?&callback=myCallback"></script>
returns either [object object] or undefined... something is still wrong? the contents of test.json is myCallback( {"your":"json"} );
I'm trying to download some data using pure javascript/html from cross-domain, dropbox to be specific.
<html>
<head>
</head>
<body>
<div id = 'twitterFeed'></div>
<script>
function myCallback(dataWeGotViaJsonp){
var text = '';
var len = dataWeGotViaJsonp.length;
for(var i=0;i<len;i++){
twitterEntry = dataWeGotViaJsonp[i];
text += '<p><img src = "' + twitterEntry.user.profile_image_url_https +'"/>' + twitterEntry['text'] + '</p>'
}
document.getElementById('twitterFeed').innerHTML = text;
}
</script>
<script type="text/javascript" src="http://dl.dropbox./u/6438697/padraicb.json?count=10&callback=myCallback"></script>
</body>
for some reason, the json is not loading. however the json loads correctly when I make the url "http://twitter./status/user_timeline/padraicb.json?count=10&callback=myCallback" instead. I got this example from here
Can anybody explain why dropbox doesn't work?
thanks!
UPDATE:
<script type=text/javascript>
function myCallback(dataWeGotViaJsonp){
alert(dataWeGotViaJsonp);
}
</script>
<script type="text/javascript" src="http://dl.dropbox./u/6438697/test2?&callback=myCallback"></script>
returns either [object object] or undefined... something is still wrong? the contents of test.json is myCallback( {"your":"json"} );
Share Improve this question edited May 23, 2017 at 12:06 CommunityBot 11 silver badge asked Aug 6, 2011 at 3:43 ejangejang 4,0628 gold badges46 silver badges71 bronze badges 1-
1
Re: the update, you're alerting the object. To alert the string
json
,alert(dataWeGotViaJsonp.your);
– Yahel Commented Aug 6, 2011 at 12:35
2 Answers
Reset to default 6You can't just add the word 'callback' to your URL and expect Dropbox to wrap it for JSONP. You put a JSON file on your Dropbox and shared it publicly, but Dropbox isn't a dynamic server. You need a scriptable environment to take the callback parameter value and wrap it around the JSON in order to make it "JSONP".
The reason the Twitter URL works is that their API is configured to take the callback parameter as a sign that the client is expecting JSONP, which is really just a fancy term for "a JavaScript object literal wrapped in a callback function". You tell twitter what that function will be called, and they'll return a file that the browser will execute as a script, passing the object as a parameter to your callback function.
If you don't need the JSONP callback function name to be dynamic AND you need to use Dropbox, just wrap the JSON yourself. All you need to do is edit the file, and prepend valid JSON with the name of the function, and append it with the close paren.
ie,
myCallback( {"your":"json"} );
It is possible to use Google Apps Script as a proxy for hosting sites that do not support jsonp. There is writeup on how to do it here http://ramblings.mcpher./Home/excelquirks/jsonp
本文标签: javascriptdropbox jsonp fileStack Overflow
版权声明:本文标题:javascript - dropbox jsonp file - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745313739a2653055.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论