проблема в возврате json-ответа на плагин jquery ajaxupload - PullRequest
1 голос
/ 12 июля 2010

Я использую jquery ajaxupload плагин для загрузки файлов. У меня есть следующие js на моей странице default.aspx

 $(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. Я ожидаю ответ json от upload.aspx. Но я не понимаю, как мне вернуть ответ от загрузки страницы. Я также попытался изменить действие 'attribute to' upload.aspx / getdata ', где' getdata 'является методом / webmethod, но я все еще вижу, как вызывается загрузка страницы, а не метод / webmethod.

Может ли кто-нибудь помочь мне получить ответ (например, состояние загрузки (успешно / неудачно) в json) и представить его в пользовательском интерфейсе?

1 Ответ

0 голосов
/ 12 июля 2010

.

Response.ContentType = "application/json";  
Response.Write(@"{""Name1"":""FirstValue"", ""Name2"":""SecondValue""}");

или в вашем случае:

Response.Write(@"{""Status"":""Success""}");

Сама страница upload.aspx должна быть полностью пустой.

...