0
我想從API apicontroller下載的客戶端文件使用jQuery下載:如何彈出窗口mvc4的WebAPI
public HttpResponseMessage PostOfficeSupplies()
{
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
result.Content = new StreamContent(File.OpenRead("D:\\Others\\Images\\file.png"));
result.Content.Headers.ContentType = new MediaTypeHeaderValue ("application/octet-stream");
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
result.Content.Headers.ContentDisposition.FileName = "file.png";
return result;
}
怎麼樣的客戶端代碼(視圖)與jQuery彈出一個下載我?
我的客戶端:
$.ajax(
{
url: 'api/MyAPI'
, type: "post"
, contentType: "application/octet-stream"
, data: ''
, success:
function (retData) {
$("body").append("<iframe src='" + retData + "' style='display: block;' ></iframe>");
$("#sp123").text(retData);}
});
我只想彈出一個下載
從你的表述來看,我不清楚jQuery和這些有什麼關係?最後,您只需鏈接到控制器上的操作;你怎麼做並不特別重要。 – Heather
使用jquery從HttpResponseMessage(服務器)開始下載我更新了問題 – Ray