2012-09-18 69 views
3

在我的Windows小工具代碼在SettingsClosing(event)中使用jQuery發出ajax(POST)調用。我通過Fiddler觀看ajax呼叫執行。 Ajax調用正在返回所需的結果,但它不會觸發成功的回調ajax。我試圖在的onPageLoad相同的代碼(主視圖)事件是在那裏工作很好,我的代碼是這樣的Windows 7邊欄小工具,沒有得到結果的Ajax調用

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); 

    } 
} 

任何幫助表示讚賞。

回答