dropbox jsonp file

后端 未结 2 1390
隐瞒了意图╮
隐瞒了意图╮ 2021-01-21 08:22

I\'m trying to download some data using pure javascript/html from cross-domain, dropbox to be specific.





             


        
相关标签:
2条回答
  • 2021-01-21 09:05

    You 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"}  );
    
    0 讨论(0)
  • 2021-01-21 09:13

    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.com/Home/excelquirks/jsonp

    0 讨论(0)
提交回复
热议问题