在我的 Windows 小工具代码中,在 SettingsClosing(event) 中使用 jQuery 进行了 ajax (POST) 调用。我通过Fiddler观看 ajax 调用执行。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);
}
}
任何帮助表示赞赏。