来自PHP的Dropzone调试和ajax消息

时间:2022-10-08 21:15:45

I'm using latest Dropzone.js release 3.7.1 and PHP script to upload file to server

我用最新的Dropzone。js发行版3.7.1和PHP脚本上传文件到服务器

I'm would like to get message back to drop zone area, on image so i exit with

我想要得到消息,以下降区域,在图像上,所以我退出

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

this display a generic dropzone error on image but if i use

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

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

I get "Invalid JSON response from server."

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

if i use

如果我使用

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

i get "[object Object]"

我得到“对象对象”

Does drop zone pass file upload as an array or as a single file?

删除区域是否将文件上载为数组或单个文件?

1 个解决方案

#1


9  

You can set the response Content-Type to text/plain and just send the message, or set the Content-Type to application/json and send {"error": "message"}.

您可以将响应内容类型设置为text/plain,然后只发送消息,或者将内容类型设置为application/json,并发送{“error”:“message”}。

In both cases you need to send an error header, otherwise Dropzone will not interpret the response as an error:

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

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

#1


9  

You can set the response Content-Type to text/plain and just send the message, or set the Content-Type to application/json and send {"error": "message"}.

您可以将响应内容类型设置为text/plain,然后只发送消息,或者将内容类型设置为application/json,并发送{“error”:“message”}。

In both cases you need to send an error header, otherwise Dropzone will not interpret the response as an error:

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

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