I've got the following response from dropzone successful upload.
我从dropzone成功上传得到以下回复。
From this I need to fetch the responseText
从这里我需要获取responseText
I tried: console.log(response.xhr.responseText)
this show the full response text.
我试过:console.log(response.xhr.responseText)这个显示完整的响应文本。
When i try to fetch img
from responseText like this console.log(response.xhr.responseText.img)
the console throw undefined
当我尝试从这个console.log(response.xhr.responseText.img)的responseText中获取img时,控制台抛出undefined
3 个解决方案
#1
6
In your sample, the value of rexponse.xhr.responseText
is a string, not an object. You can parse the string into an object and access the img
property:
在您的示例中,rexponse.xhr.responseText的值是字符串,而不是对象。您可以将字符串解析为对象并访问img属性:
(JSON.parse(response.xhr.responseText)).img
...but, since Dropzone success
events get both the file
object and the parsed responseText
, you could write a success
handler like this:
...但是,由于Dropzone成功事件同时获取文件对象和解析后的responseText,您可以编写成功处理程序,如下所示:
new Dropzone("#myUploader", {
url: "/upload",
init: function () {
this.on("success", function (file, responseText) {
console.log(responseText.img);
});
}
});
for more information, check out the FAQ.
有关更多信息,请查看常见问题解答。
#2
1
Saurabh solution is working for me after making some changes, beacuse i was getting
Saurabh解决方案在做了一些改变后为我工作,因为我得到了
Uncaught SyntaxError: Unexpected token o
未捕获的SyntaxError:意外的令牌o
when trying
init: function () {
this.on("success", function (file, responseText) {
var responsetext = JSON.parse(responseText);
console.log(responsetext.file_name); });
so i made some changes in it and its working for me.
所以我做了一些改变,它为我工作。
this.on("success", function (file) {
var responsetext = JSON.parse(file.xhr.responseText);
console.log(responsetext);});
#3
0
new Dropzone("#myUploader", { url: "/upload", init: function () { this.on("success", function (file, responseText) { var responsetext = JSON.parse(responseText); console.log(responsetext.file_name); }); } });
new Dropzone(“#myUploader”,{url:“/ upload”,init:function(){this.on(“success”,function(file,responseText){var responsetext = JSON.parse(responseText); console.log (responsetext.file_name);});}});
#1
6
In your sample, the value of rexponse.xhr.responseText
is a string, not an object. You can parse the string into an object and access the img
property:
在您的示例中,rexponse.xhr.responseText的值是字符串,而不是对象。您可以将字符串解析为对象并访问img属性:
(JSON.parse(response.xhr.responseText)).img
...but, since Dropzone success
events get both the file
object and the parsed responseText
, you could write a success
handler like this:
...但是,由于Dropzone成功事件同时获取文件对象和解析后的responseText,您可以编写成功处理程序,如下所示:
new Dropzone("#myUploader", {
url: "/upload",
init: function () {
this.on("success", function (file, responseText) {
console.log(responseText.img);
});
}
});
for more information, check out the FAQ.
有关更多信息,请查看常见问题解答。
#2
1
Saurabh solution is working for me after making some changes, beacuse i was getting
Saurabh解决方案在做了一些改变后为我工作,因为我得到了
Uncaught SyntaxError: Unexpected token o
未捕获的SyntaxError:意外的令牌o
when trying
init: function () {
this.on("success", function (file, responseText) {
var responsetext = JSON.parse(responseText);
console.log(responsetext.file_name); });
so i made some changes in it and its working for me.
所以我做了一些改变,它为我工作。
this.on("success", function (file) {
var responsetext = JSON.parse(file.xhr.responseText);
console.log(responsetext);});
#3
0
new Dropzone("#myUploader", { url: "/upload", init: function () { this.on("success", function (file, responseText) { var responsetext = JSON.parse(responseText); console.log(responsetext.file_name); }); } });
new Dropzone(“#myUploader”,{url:“/ upload”,init:function(){this.on(“success”,function(file,responseText){var responsetext = JSON.parse(responseText); console.log (responsetext.file_name);});}});