Frage

In my windows gadget code in made an ajax (POST) call using jQuery in SettingsClosing(event). I watch the ajax call execution through Fiddler. Ajax call is returning the desired results.But it is not triggering success callback ajax. I tried the same code in OnPageLoad() event of main view it is working fine there, My code is like this

function Login(username, password) {
    var url = "http://example.com/Auth.php";
    var data = { pusername: username, ppassword: password };
    jQuery.support.cors = true;
    $.ajax({
        type: "POST"
            , dataType: "json"
            , url: url, data: data
            , success: function (refresh_token) {
                System.Gadget.Settings.write("success", "true");
                System.Gadget.Settings.write("dd", refresh_token);
                var tok = refresh_token['refreshtoken'];
                var name = refresh_token['name'];
                System.Gadget.Settings.write("name", name);
                System.Gadget.Settings.write("refreshtoken", tok);

            }
                , error: function (XMLHttpRequest, textStatus, errorThrown) {
                    System.Gadget.Settings.write("login_error", errorThrown);
                    System.Gadget.Settings.write("login_STATUS", textStatus);
                }
    });
}

function SettingsClosing(event) 
{
    //use this question to now if setting was closed with OK button
    if (event.closeAction == event.Action.commit)
    {
        var username = $('#txtpUsername').val();
        var password = $('#txtpPassword').val();
        Login(username, password);

    }
}

Any help is appreciated.

War es hilfreich?

Lösung

Because the ajax call is asynchronous, it would seem likely that the code doesn't have the opportunity to run before the operation completes. You could try setting event.cancel to true, and then triggering the close manually after your ajax call completes. MSDN reference: http://msdn.microsoft.com/en-us/library/windows/desktop/ms723677(v=vs.85).aspx

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top