从悬浮窗的Ajax响应获取响应文本 [英] fetch response text from ajax response of a dropzone

查看:174
本文介绍了从悬浮窗的Ajax响应获取响应文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经接到了悬浮窗上传成功以下响应。

I've got the following response from dropzone successful upload.

在此我要取的responseText

From this I need to fetch the responseText

我想:的console.log(response.xhr.responseText)这显示完整的响应文本

I tried: console.log(response.xhr.responseText) this show the full response text.

当我尝试获取 IMG 从responseText的像这样的的console.log(response.xhr.responseText.img)控制台掷未定义

When i try to fetch img from responseText like this console.log(response.xhr.responseText.img) the console throw undefined

推荐答案

在你的样品, rexponse.xhr.responseText 的值是一个字符串,而不是一个对象。您可以分析字符串转换为对象并访问 IMG 属性:

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

...但是,由于悬浮窗成功活动获得文件对象,无论是解析的responseText ,你可以写一个成功处理程序是这样的:

...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);
      });
    }
});

有关更多信息,请访问<一个href="https://github.com/enyo/dropzone/wiki/FAQ#i-want-to-display-additional-information-after-a-file-uploaded"相对=nofollow>常见问题。

for more information, check out the FAQ.

这篇关于从悬浮窗的Ajax响应获取响应文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆