I've got the following response from dropzone successful upload.
From this I need to fetch the responseText
I tried: console.log(response.xhr.responseText)
this show the full response text.
When i try to fetch img
from responseText like this console.log(response.xhr.responseText.img)
the console throw undefined
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:
(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:
new Dropzone("#myUploader", {
url: "/upload",
init: function () {
this.on("success", function (file, responseText) {
console.log(responseText.img);
});
}
});
for more information, check out the FAQ.
Saurabh solution is working for me after making some changes, beacuse i was getting
Uncaught SyntaxError: Unexpected token 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);});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With