views:

52

answers:

1

hi, 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 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>    

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?

A: 

.

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.

James Curran
thanks James.Instead of printing it to the screen directly from Upload.aspx page,I want to send the json response to AjaxUpload method.how is that possible?
kranthi
Upload.aspx is a simple program which merely generates some text. If your browser called Upload.aspx, then the browser would get the results and display it in its window. However, here, AjaxUpload has called Upload.aspx, and it's AjaxUpload that will receive the text it produces.
James Curran
Ok,so if I do a reponse.write after the upload has finsished,my browser will display the message in the Default.aspx,which made the request.is that correct?
kranthi
James Curran
sorry for the confusion.so I hope its this way.The Ajaxupload method receives the response.write text from the upload.aspx page and I'll have to handle presenting it in the browser from the Ajaxupload method
kranthi
(While doing a google search, I discovered where you found that code. I'd though you'd written it, so I was assuming a higher level of understanding.) After Upload.aspx completes, the OnComplete() js code is run, being passed as parameters, the name of the file and the json returned from upload.aspx. In the OnComplete, which presently does nothing with the response parameter, must evaluate that for status==success, and deal with that as you wish.
James Curran