【问题标题】:Dropzone debug and ajax messages from PHP来自 PHP 的 Dropzone 调试和 ajax 消息
【发布时间】:2013-11-28 14:46:25
【问题描述】:

我正在使用最新的 Dropzone.js 版本 3.7.1 和 PHP 脚本将文件上传到服务器

我想将消息返回到拖放区,在图片上 所以我退出了

header('HTTP/1.1 500 Internal Server Error');
header('Content-Type: application/json');
exit();

这会在图像上显示一个通用的 dropzone 错误 但如果我使用

header('HTTP/1.1 500 Internal Server Error');
header('Content-Type: application/json');
exit("My error");

我收到“来自服务器的无效 JSON 响应。”

如果我使用

header('HTTP/1.1 500 Internal Server Error');
header('Content-type: application/json');
exit(json_encode(array('message' => '$msg', code => 500)));

我得到“[对象对象]”

拖放区是以数组还是单个文件的形式上传文件?

【问题讨论】:

    标签: javascript php ajax dropzone.js


    【解决方案1】:

    您可以将响应 Content-Type 设置为 text/plain 并发送消息,或者将 Content-Type 设置为 application/json 并发送 {"error": "message"}

    在这两种情况下都需要发送错误头,否则 Dropzone 不会将响应解释为错误:

    header('HTTP/1.1 500 Internal Server Error');
    header('Content-type: text/plain');
    exit("My error");
    

    【讨论】:

      猜你喜欢
      • 2014-07-22
      • 1970-01-01
      • 2013-08-14
      • 2017-06-23
      • 1970-01-01
      • 1970-01-01
      • 2022-06-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多