如何在表单操作中传递url ajax

时间:2017-01-24 02:05:00

标签: javascript jquery ajax dropbox-api dropzone.js

我正在尝试将Dropzone添加到我的Dropbox API中,我想知道如何将我的ajax的值传递给我的form action = "*"因为当我删除操作时它说Dropzone : Uncaught Error: No URL provided但是当我放置我的特定端点时它说Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin'但是我的ajax标题中有一个授权

这是我的代码

<html>
<script src='//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js' type='text/javascript'></script>
<script src="https://rawgit.com/enyo/dropzone/master/dist/dropzone.js"></script>

<link rel="stylesheet" href="https://rawgit.com/enyo/dropzone/master/dist/dropzone.css">

<form action="https://content.dropboxapi.com/2/files/upload" type="file" id="files" name="files[]" multiple  class = "dropzone">


</form>



<script>

 function handleFileSelect(evt) {
 var files = evt.target.files; // FileList object

 // files is a FileList of File objects
 for (var i = 0, file_name; file_name = files[i]; i++) {

 $.ajax({
 url: 'https://content.dropboxapi.com/2/files/upload',
 type: 'post',
 data: file_name,
 processData: false,
 contentType: 'application/octet-stream',
 headers: {
 "Authorization": "Bearer ACCESS TOKEN",
 "Dropbox-API-Arg": '{"path": "/' + file_name.name + '","mode": "add"}'
 },
 success: function (data) {
    alert('The file has been uploaded!');

 console.log(data);

 },
 error: function (data) {
 console.log(data);
 }



 })

 }



 }

 document.getElementById('files').addEventListener('change', handleFileSelect, false);

</script>

</html>

0 个答案:

没有答案