javascript - DropzoneJS : How to get PHP response after upload success?

标签 javascript php dropzone.js

我正在尝试在我的网站上实现 Dropzone。我想监听“成功”事件,然后获取服务器响应,并在上传完成后将一些信息添加到与 DropZone 相同页面上的表单中。

我想在服务器响应中获得的信息是文件的直接链接。

dropzone网站:http://www.dropzonejs.com/

我的项目网站:

http://37.34.62.131/test/

所以我在我的项目的旧版本中完成了这项工作,但我无法弄清楚如何使用 dropzone.js 完成这项工作

工作示例:

http://37.34.62.131/test/uploader%201.0/

我尝试做的是,当文件上传后,我想在同一页面上获取 php 响应,下载链接如下所示。

我也可以将我的源代码发送给您,以便您自己查找。

我想在响应中看到我的 php 代码:

        print '<h2>Picture Uploaded Successfuly!!!!</h2> <p id="codes">

      <img src="'.$imgurl.'" height="300" alt="Uploaded Picture" >
        <label for="codebb">BBCode:</label>
        <input type="text" id="codebb" value="[URL='.$siteurl.'][IMG]'.$dlurl.'[/IMG][/URL]" onclick="javascript:this.focus();this.select();" readonly="true" /><br />
        <label for="codehtml">HTML Code: </label>
        <input type="text" id="codehtml" value=\'&lt;a href="'.$siteurl.'"&gt;&lt;img src="'.$dlurl.'" alt="'.$alt.'" /&gt;&lt/a&gt;\' onclick="javascript:this.focus();this.select();" readonly="true" /><br />
        <label for="codedirect">Direct Link:</label>
        <input type="text" id="codedirect" value="'.$dlurl.'" onclick="javascript:this.focus();this.select();" readonly="true" /></p>';
        echo ".$newname";

谁能帮我理解我错过了什么?

最佳答案

查看您的网站,您似乎能够解决问题。

无论如何,这是给可能仍在寻找的人的。您需要添加带有两个参数的函数 success。返回的第一个参数总是文件,第二个是响应。

One of the other answers had this, but this response did not initially include it. It's important to set the autoDiscover to false, or this example (as provided in the docs) does not work. Tested on Chrome/IE/Edge on Win10.

示例:

Dropzone.autoDiscover = false;

$(function() {
        Dropzone.options.uiDZResume = {
            success: function(file, response){
                alert(response);
            }
        };
    });

关于javascript - DropzoneJS : How to get PHP response after upload success?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19390471/

相关文章:

javascript - 如何通过单击另一个按钮使按钮可见?

javascript - 一键关闭windows工具编译文件夹内所有js文件

php - 如何在纯php页面中使用javascript函数

php - Symfony 表单 : customize the setter that is called

javascript - 使用不带表单的 dropzone.options

javascript - 模板助手中的 Meteor QuickForm 异常 : Error: Recipes is not in the window scope

javascript - 使用 Javascript 在另一个动态元素内创建一个动态元素

php - 如何在 Amazon S3 上生成缩略图?

javascript - hapi.js Cors 飞行前不返回 Access-Control-Allow-Origin header

javascript - 降落区 : Uncaught Error: No URL provided