简体   繁体   English

使用jquery文件上传插件从服务器获取文本响应

[英]fetching text response from the server using jquery file upload plugin

My server returns a simple string which I want to alert out and append to a div. 我的服务器返回一个简单的字符串,我想提醒并追加到div。 So I do the following in jquery file upload 所以我在jquery文件上传中执行以下操作

$('#fileupload').fileupload({
    dataType: 'text',
    done: function (data) {
        alert(data)
       $('#result').html(data); 
    }
});

I've also tried this variation 我也试过这种变化

$('#fileupload').fileupload({
    dataType: 'html',
    done: function (e, data) {
        alert(data)
       $('#result').html(data); 

    }
});

however, the alert shows 'Object' and the #result div is not updated with the response. 但是,警报显示'Object' ,而#result div未随响应更新。 I've seen the response using firebug and he response does infact come from the server and it is simply a string. 我已经看到使用firebug的响应,他的响应确实来自服务器,它只是一个字符串。

Update 更新

after some debugging I found this code to be working fine, but not sure if this is the best way to do this. 经过一些调试后,我发现这段代码工作正常,但不确定这是否是最好的方法。

$('#fileupload').fileupload({
    dataType: 'text',
    done: function (e, data) {
        console.log("done", data.result);
       $('#result').html(data.result); 

    }
});

If you use FireBug for Firefox, or Chrome, press F12 and place a debugger; 如果您使用FireBug for Firefox或Chrome,请按F12并放置一个debugger; statement before the alert statement. alert声明前的声明。
Javascript debugger (any of it) will pause on this line so you can explore the value of the data variable. Javascript调试器(其中任何一个)将在此行上暂停,以便您可以探索data变量的值。 It seems to be a structure, not just plain text. 它似乎是一种结构,而不仅仅是纯文本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM