开发者

jquery ajax callback difficulty

I have the following code:

$.ajax({
                // type: "POST",
                url: webMethod,
                data: $.toJSON(params),
                // dataType: "json",
                // contentType: "application/json",
                success: function (obj) {

                    if (obj == 1) {
                        window.location = 'Postpaid/Dashboard';
                        // $.mobile.changePage('#dashboard', 'slide', false, true);
                    }
                    else if (obj == 0) {
                        window.location = 'Prepaid/Dashboard';
                    }
                    else if (obj == -1) {
                        window.location = 'Home/Index/#login1';
                    }
                    else {
                        $.mobile.changePage('#login2', 'slide', false, true);

                        $('#txtMSISDN2').val(obj.Pin.MSISDN);
                        $('#txtPin').val(obj.Pin.PIN);
                        $('#txtMSISDN2').attr('readonly', 'readonly');
                    }
                },
                error: function () {
                    alert('error returned.');
                }
            });

From the method 开发者_运维百科I return a flag integer. I want to redirect the user to the appropriate webpage according to the return int. However, this code doesn't work. Any suggestions?

Do i use window.location incorrectly here? Thank you very much!

Thanks in advance!


My feedback...

  1. the data could be directly your params, no need to use $.toJSON

  2. add a console.debug(obj) to see what's really returned by JQM (and not just Fiddler)

  3. replace those window.location with $.mobile.changePage, that's why it's there (and will take care of other stuff for you as well)

Once you tells us what #2 returns, we'll be able to provide better solutions to your problem.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜