Link to home
Start Free TrialLog in
Avatar of 3161
3161

asked on

Redirection in Javacsript

I am doing an ajax call to a handler in C# and the handler is returning a successful response. I am try to direct the user to the proper url based on the response So the return value looks like this:

{'Auth':'true', 'URL':'Default.aspx'}

And the call looks like this:

   
$('#cmdSubmit').on('click', function () {


            var _username = $.trim($('#txtUsername').val());
            var _password = $.trim($('#txtPassword').val());
            var _formData = { 'func': 'Auth', 'Username': _username, 'Password': _password };

            $.ajax({
                url: _profileHdlr,
                async: false,
                type: 'GET',
                data: _formData,
                'dataType': 'json',
                success: function (data) {
                    alert(data.Url);     // Th alert fires just fine
                    window.location.href = data.Url;   // The window.location does nothing
                },
                error: function (jqXHR, error, errorThrown) {
                    if (jqXHR.status && jqXHR.status == 400) {
                        alert(jqXHR.responseText);
                    }
                }
            });
        }

Open in new window


I realize this seems simple, I think so also, but the redirection does not work. I already tried window,location.assign and .replace but nothing happens. If anyone has any ideas I would be grateful.
Avatar of Insoftservice inso
Insoftservice inso
Flag of India image

try out this method too
Please paste alert value.

1 > window.navigate("http://lovetomarry.com");
2> self.location="http://lovetomarry.com";
3> top.location="http://lovetomarry.com";
Avatar of 3161
3161

ASKER

I appreciate the quick reply, and believe me I have done this before, so I am very confused about why it is behaving this way. I tried your suggestions and it simply does nothing. I realize I am not giving you anything to go on, but I don't have anything.

The alerts simply posts the page which I want to redirect to, in this case Default.aspx.

Thanks again
i hope value is http://desired url/default.aspx

var url = data.Url;
window.location.href = url;
Avatar of 3161

ASKER

Once again thank you for your reply.  To remove any possibility to formatting problems I modified the code to read:

            $.ajax({
                url: _profileHdlr,
                async: false,
                type: 'GET',
                data: _formData,
                'dataType': 'json',
                success: function (data) {                    
                    window.location.href = "http://lovetomarry.com";
                    //alert(data.Url);
                },
                error: function (jqXHR, error, errorThrown) {
                    if (jqXHR.status && jqXHR.status == 400) {
                        alert(jqXHR.responseText);
                    }
                }
            });


Unfortunately I still receive nothing, I even uploaded the code to eliminate the possibility of the localhost being the problem (although it never has been before)

Thank you again
Confused
ASKER CERTIFIED SOLUTION
Avatar of Insoftservice inso
Insoftservice inso
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 3161

ASKER

I am currently working with Chrome, but I just tried in IE and FireFox and I get the same results. The start page is a Login.aspx, which calls a .js file and contains the code I included with this message.

The .js file makes an ajax call to a handler which authenticates the user and returns the values listed. All this works with no issues. The alert fires but the redirect on the window just sits there.

Not sure if any of that helps, but I thought I would try to detail the process to help in figuring out what the problem is.

I will keep working on it and let you now if I find anything.

Thanks again
Avatar of 3161

ASKER

I am not sure if this will help determine the problem, but in trying to troubleshoot it in Firefox, if I step through it using Firebug, it redirects, if I remove the break point, nothing happens . . . weird
Did u added return false; after redirection code.
Avatar of 3161

ASKER

Thank you once again for your response. I also tried return false but still received the same results. There is obviously something else in the application interfering with the redirect. To minimize cost and time I have gone in another direction.

I appreciate everyone's help but this question should be closed.

Thank you again
CJSantora
Avatar of 3161

ASKER

Expert spent some time trying to help with my issue and was very responsive.