【发布时间】:2014-12-28 03:18:37
【问题描述】:
我正在尝试按照example 显示进度条,而不使用 ajax 下载文件。
我使用淘汰赛、html 和 webapi。我有下面的代码,它在按钮的点击事件上调用 href
this.getMeData= function () {
uRlPath("/api/GetSomeData?id=" + 12)
+ "&name=" + getName.toString()
+ "&downloadtoken=" + new Date().getTime());
$('#myLink').click();
location.href = $('#myLink').attr('href');
};
这是我的html
<tr>
<td class="labelText">
<button data-bind="click: getMeData">
Download Data
</button>
</td>
</tr>
<tr>
<td>
<a id="myLink" data-bind="attr: { href: uRlPath }" style="visibility: hidden">Open </a>
</td>
</tr>
我现在想在我的 href 的点击事件上调用一些函数
这是我的 webapi 方法,它返回我的 cookie 和二进制文件
public HttpResponseMessage GetSomeData(int id, string name, string downloadtoken)
{
var returnData= new HttpResponseMessage(HttpStatusCode.OK);
returnData.Content = new ByteArrayContent(mybyteArray);
var cookie = new CookieHeaderValue("downloadtoken", downloadtoken);
returnData.Headers.AddCookies(new CookieHeaderValue[] { cookie });
returnData.Content.Headers.ContentDisposition =
new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");
returnData.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
returnData.Content.Headers.ContentDisposition.FileName = "myfile.pdf";
return returnData;
}
非常准确地说,我希望具有与示例中提供的相同的行为。例如,他们使用表单提交,但我没有任何表单,因为我只使用 html,敲除。我已经包含了示例中提到的所有库。
如果您需要更多输入,请告诉我。
【问题讨论】:
标签: javascript jquery html knockout.js asp.net-web-api