gpt4 book ai didi

javascript - document.location 尝试下载文件时修改 WebApi 路由

转载 作者:行者123 更新时间:2023-12-03 07:55:26 25 4
gpt4 key购买 nike

我有一个使用 AngularJs 和 WebApi 构建的应用程序。我试图在按下按钮时下载文件。这是 ng-click 的代码:

                $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 中。我注意到运行此代码后,WebApi 的 URL 在 IE 中非常不同。更具体地说:

我正在使用的 View 具有以下 URL:http://localhost:54094/admin/studies/edit/1在调用应该开始下载的 ng-click 函数后,我看到以下结果:

因此,在 IE 中,不会调用正确的 WebApi 服务。

我错过了什么或做得不对吗?任何提示将不胜感激。

谢谢。

最佳答案

应该使用绝对路径而不是相对路径...只需添加 /

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

浏览器将查找api假设您没有使用 <base> 站点根目录中的目录页面中的标签

关于javascript - document.location 尝试下载文件时修改 WebApi 路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34819694/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com