“error”: “Invalid origin” using dropbox chooser

北城余情 提交于 2019-12-10 05:47:03

问题


<!DOCTYPE html>
<html>
<head>
 <title>DropBox Chooser Example</title>
</head>
<body>
 <div id="main">
  <input type="dropbox-chooser" name="selected-files" data-link-type="direct" id="db-chooser"/>
  <div id="content"></div>
 </div>

<script type="text/javascript" src="https://www.dropbox.com/static/api/1/dropins.js" id="dropboxjs" data-app-key="YOUR-APP-KEY"></script>
<script type="text/javascript" src="jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="jquery.tools.min.js"></script>
<script type="text/javascript" src="jquery-layout.js"></script>
<script type="text/javascript">

$(function(){

    var dbChooser = $("#db-chooser");

    dbChooser.on("DbxChooserSuccess", function(e) {

        // Here we will listen when a file is
        // chosen from dropbox, insert it into the page
        // and initialize the Jcrop plugin
        e = e.originalEvent;
       var name = e.files[0].name;
    });
});
</script>
</body>
</html>

This is my example code in which i am trying to implement the dropbox chooser. I have created an app and i do pass the app key. The errors i encounter are,

  1. Initially on page load, i get the error that $(...).on is not a function.

  2. When i click on the dropbox chooser button, i get {"error": "Invalid origin"}.

I am not getting where i am going wrong. Any help will be appreciated.


回答1:


I ran into, and was able to resolve, this same issue today. The Dropbox Chooser functionality does not support file browsing unless the script is running on a web server. If you are testing your web app locally and are accessing it via a file:// link, you will get the 'invalid origin' error. Instead, run a web server (either locally or hosted somewhere else) with your web app on it, and that should eliminate the error.



来源:https://stackoverflow.com/questions/16412023/error-invalid-origin-using-dropbox-chooser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!