0

I got a fairly simple WinJS Metro app which gets asks the user for a username and password before getting some JSON-data from a webservice.

I use jQuery.ajax() to get the data, and i set the basic authentication header correctly. However, if the user enters incorrect credentials, and the server returns a 401, the metro runtime displays a login screen. The error handler passed to the jQuery.ajax() function isn't called unless the user presses "cancel" on the runtime provided login screen.

I want the program to handle failed login attempts, is there a way to suppress the runtime logon screen?

madsny
  • 121
  • 6

1 Answers1

0

Not sure what you're doing, but the following code properly triggers the error handler if the user provides the wrong username/password:

    var userInfo = getCurrentUserInfo();
    $.ajax({
        url: URL,
        dataType: 'json',
        success: jsonCallback,
        username: userInfo.username,
        password: userInfo.password,
        error: function (jqXHR, textStatus, errorThrown) {
            errorHandler(jqXHR, textStatus, errorThrown);
        }
    }

Are you providing the username/password on your own, or waiting for the system's login dialog to come up? I'm afraid once it comes up, there's no getting back to your code until the user cancels, like you say.

Pablo D.
  • 620
  • 6
  • 15
  • you're right, if I use the `username` and `password` options to `$.ajax`, the error handler is hit. I used the `header` option like this: `headers: {"Authorization": "Basic " + encode.base64(username + ':' + password)},...` - which I thought would be equivalent – madsny Sep 17 '12 at 16:55
  • jQuery has mysterious ways! Glad to help. – Pablo D. Sep 19 '12 at 16:48