problem in returning a json response to jquery ajaxupload plugin
I am using jquery ajaxupload plugin to upload files .I have the following js on my default.aspx page
$(document).ready(function() {
/* Example 1 */
var button = $('#button1'), interval;
new AjaxU开发者_JAVA百科pload(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>
the above js will invoke upload.aspx.cs page load.I am expecting a json response from upload.aspx.But I do not understand how do I return a response from page load.I have also tried modifying the 'action' attribute to 'upload.aspx/getdata', where 'getdata' is a method/webmethod,but I still see the page load getting invoked and not the method/webmethod.
Could someone please help me in getting a response(such as upload status(success/fail) in json) and presenting it to the UI?
.
Response.ContentType = "application/json";
Response.Write(@"{""Name1"":""FirstValue"", ""Name2"":""SecondValue""}");
or in your case:
Response.Write(@"{""Status"":""Success""}");
The upload.aspx page itself should be completely empty.
精彩评论