开发者

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

I have a开发者_JS百科n asp.net page with a long running task and a jquery ajax call for the progress bar. On success, I want to pass back a int for the progress but also some text for status like what record I'm on.

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?

I thought an array or class but it isn't working.

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 :

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

, then you should just need to Parse the returned json string into an Object, for example :

 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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜