2016-01-15 18 views
0

我有一個使用AngularJs和WebApi構建的應用程序。我試圖按下按鈕時下載文件。這是ng-click的代碼:document.location在嘗試下載文件時修改WebApi路由

   $scope.download = function (documentObj) { 
       if (documentObj && documentObj.FileName) 
       { 
        var urlParams = "sId=" + documentObj.IdStudy + "&fId=" + documentObj.IdRequiredFile + "&fName=" + documentObj.FileName; 

        document.location = "api/document/download?" + urlParams; 
       } 
      }; 

這在Chrome和Mozilla中運行良好,但在IE中沒有。在任何IE中。 我注意到在運行此代碼後,IE中的WebApi的URL與IE非常不同。更具體地講:

我在快樂工作的觀點有這個網址:http://localhost:54094/admin/studies/edit/1 後,我打電話應該開始下載我看到下面的結果NG-點擊功能:

因此,在IE中,正確的WebAPI服務不被調用。

我在想什麼或者做不對?任何提示將不勝感激。

謝謝。

回答

1

應在

頁中使用絕對路徑,而不是相對一個...只需添加一個 /

document.location = "/api/document/download?" + urlParams; 

瀏覽器將查找在網站的根目錄api假設你沒有使用過<base>標籤