简体   繁体   English

asp.net 和 jquery ajax 成功返回一个以上的值

[英]asp.net and jquery ajax returning more then one value on success

I have an asp.net page with a long running task and a jquery ajax call for the progress bar.我有一个 asp.net 页面,其中包含一个长时间运行的任务和一个 jquery ajax 调用进度条。 On success, I want to pass back a int for the progress but also some text for status like what record I'm on.成功时,我想传回一个 int 来表示进度,但也想传回一些状态文本,比如我正在使用的记录。

What I have below I know isn't right but how can I get more then one value returned?我知道下面的内容是不正确的,但是我怎样才能得到一个以上的返回值?

What is the proper syntax on 'msg' to get both values?获取两个值的“msg”的正确语法是什么?

I thought an array or class but it isn't working.我认为一个数组或 class 但它不起作用。

function updateProgress() {            
       $.ajax({
                type: "POST",
                url: "Users.aspx/GetProgress",
                data: "{}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                async: true,
                success: function(msg) {
                    $("#result").text = msg.Status;
                    var value = $("#progressbar").progressbar("option", "value");
                    if (value < 100) {
                        $("#progressbar").progressbar("value", msg.Progress);
                    }
                }
            });
    } 

your page should return a Json string such as:您的页面应返回 Json 字符串,例如:

["Progress" : 1, "Status" : "Current Status"]

, then you should just need to Parse the returned json string into an Object, for example: ,那么您只需要将返回的 json 字符串解析为 Object,例如:

 async: true,
 success: function(msg) {
     var obj = jQuery.parseJSON(msg);
     $("#result").text = obj.Status;
     var value = $("#progressbar").progressbar("option", "value");
          if (value < 100) {
                    $("#progressbar").progressbar("value", obj.Progress);
                }
            }

Hope that helps, Dave希望有帮助,戴夫

For Reference: http://api.jquery.com/jQuery.parseJSON/供参考: http://api.jquery.com/jQuery.parseJSON/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM