【发布时间】:2010-07-12 15:55:26
【问题描述】:
我正在使用jquery ajaxupload插件上传文件。我的default.aspx页面上有以下js
$(document).ready(function() {
/* Example 1 */
var button = $('#button1'), interval;
new AjaxUpload(button, {
action: 'upload.aspx',
name: 'myfile',
responseType:'json',
onSubmit: function(file, ext) {
// change button text, when user selects file
button.text('Uploading');
// If you want to allow uploading only 1 file at time,
// you can disable upload button
this.disable();
// Uploding -> Uploading. -> Uploading...
interval = window.setInterval(function() {
var text = button.text();
if (text.length < 13) {
button.text(text + '.');
} else {
button.text('Uploading');
}
}, 200);
},
onComplete: function(file, response) {
button.text('Upload');
window.clearInterval(interval);
// enable upload button
this.enable();
// add file to the list
$('<li></li>').appendTo('#example1 .files').text(file);
}
});
}); /*]]>*/</script>
上面的 js 将调用 upload.aspx.cs 页面加载。我期待来自 upload.aspx 的 json 响应。但我不明白如何从页面加载返回响应。我也尝试过修改'动作' 属性到 'upload.aspx/getdata',其中 'getdata' 是一个方法/webmethod,但我仍然看到页面加载被调用,而不是方法/webmethod。
有人可以帮我获得响应(例如 json 中的上传状态(成功/失败))并将其呈现给 UI 吗?
【问题讨论】: