2017-02-15 69 views
2

我的應用程序使用外部API創建owncloud用戶。如何在自己的雲中創建使用外部API的用戶

我嘗試使用外部API獲取owncloud版本。下面是我使用的代碼:

$.ajax({ 
       type: 'GET', 
       url: 'http://localhost/owncloud/index.php/apps/news/api/2.0/version', 
       contentType: 'application/json', 
       success: function (response) { 
        // handle success 
       }, 
       error: function() { 
        // handle errors 
       }, 
       beforeSend: function (xhr) { 
        var username = 'admin'; 
        var password = 'admin'; 
        var auth = btoa(username + ':' + password); 
        xhr.setRequestHeader('Authorization', 'Basic ' + auth); 
       } 
      }); 

上面的代碼沒有工作。

如何實現這一目標?

在此先感謝。

回答

-1

您提供的代碼是正確的。

你也可以測試你的api是否使用類似postman或chrome rest client的方式返回數據。

然後(功能(響應){ $就({ 網址:網址, 類型: 「POST」, 數據類型: 「JSON」, 的contentType: 「應用程序/ JSON」, 數據:JSON。字符串化(數據), }) .done(功能(RES){ SwaI位( 「刪除了!」, 「你的ListJds已被刪除。」, 「成功」);

  }) 
      .error(function(res) { 
       res; 
       swal("Delete Failure!", "Please Try Again.", "error"); 
      }); 
     }) 
相關問題