在我的Windows小工具代码中,我使用jQuery在SettingsClosing(event)中进行了一次ajax (POST)调用。我通过Fiddler观察了这个ajax调用的执行情况。Ajax调用返回了所需的结果。但它没有触发成功回调函数。我尝试在主视图的OnPageLoad()事件中使用相同的代码,那里运行良好。我的代码如下:
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);
}
}
非常感谢您的帮助。