我使用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中获取响应(例如上传状态(成功/失败))并将其呈现给用户界面吗?
答案 0 :(得分:0)
Response.ContentType = "application/json";
Response.Write(@"{""Name1"":""FirstValue"", ""Name2"":""SecondValue""}");
或在你的情况下:
Response.Write(@"{""Status"":""Success""}");
upload.aspx页面本身应该是完全空的。